public void AddInterfaceAttachmentTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); Server server = osm.GetServer(ss.Id); Trace.WriteLine(string.Format("s.Status : {0}", server.Status)); Trace.WriteLine(string.Format("s.VMState : {0}", server.VMState)); // detach all port foreach (var _i in osm.ListInterfaceAttachments(ss.Id)) { Assert.IsTrue(osm.DeleteInterfaceAttachment(ss.Id, _i.PortId)); } // add interface var portId = GetInterfaceAttachmentIdByTesterName(); InterfaceAttachment i = osm.AddInterfaceAttachment(ss.Id, portId); try { Trace.WriteLine(string.Format("interface attachment added : {0}", DateTime.Now)); Trace.WriteLine(string.Format("PortId : {0}, NetId : {1}, MacAddress : {2}, PortState : {3}", i.PortId, i.NetId, i.MacAddr, i.PortState)); Assert.IsNotNull(i); Assert.IsNotNull(i.PortId); Assert.IsNotNull(i.NetId); Assert.IsNotNull(i.MacAddr); Assert.IsNotNull(i.PortState); } finally { // delete interface Assert.IsTrue(osm.DeleteInterfaceAttachment(ss.Id, i.PortId)); } }
static void Main(string[] args) { string username = ""; // input your user name like gncu12345678 string password = ""; // input your own password string tenantname = ""; // input your own tenant name like gnct12345678 string tenantid = ""; // input your tenant id, which is 32 characters string region = "tyo1"; var osm = new OpenStackMember( username, password, tenantname, tenantid, defaultregion: region, bLazyProviderSetting: false ); var activeServer = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); if (activeServer != null) { Console.WriteLine(String.Format("{0} is active.", activeServer.Id)); var console = osm.GetVncConsole(activeServer.Id); Console.WriteLine(console.Url); System.Diagnostics.Process.Start(console.Url); } else { Console.WriteLine("there is no active servers."); } }
public void TestMethod1() { var osm = new OpenStackMember( username, password, tenantname, tenantid, defaultregion: region, bLazyProviderSetting: false ); var activeServer = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); if (activeServer != null) { Trace.WriteLine(String.Format("{0} is active.", activeServer.Id)); var console = osm.GetVncConsole(activeServer.Id); Console.WriteLine(console.Url); System.Diagnostics.Process.Start(console.Url); } else { Console.WriteLine("there is no active servers."); } }
public void AddInterfaceAttachmentTest_2Times_Sequencely() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.ShutOff); if (ss != null) { Server server = osm.GetServer(ss.Id); Trace.WriteLine(string.Format("s.Status : {0}", server.Status)); Trace.WriteLine(string.Format("s.VMState : {0}", server.VMState)); string portId = GetInterfaceAttachmentIdByTesterName(); // the first time InterfaceAttachment i = osm.AddInterfaceAttachment(ss.Id, portId); Assert.IsNotNull(i); Assert.IsNotNull(i.PortId); Assert.IsNotNull(i.NetId); Assert.IsNotNull(i.MacAddr); Assert.IsNotNull(i.PortState); Trace.WriteLine(string.Format("interface attachment added : {0}", DateTime.Now)); Trace.WriteLine(string.Format("PortId : {0}, NetId : {1}, MacAddress : {2}, PortState : {3}", i.PortId, i.NetId, i.MacAddr, i.PortState)); // the second time, expected BadServiceRequestException but ItemNotFundException occurs AssertCatch <BadServiceRequestException>(() => i = osm.AddInterfaceAttachment(ss.Id, portId)); // delete interface Assert.IsTrue(osm.DeleteInterfaceAttachment(ss.Id, i.PortId)); } }
public void GetInterfaceAttachmentTest_Get_PortId_Not_Exist() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); InterfaceAttachment i = osm.GetInterfaceAttachment(ss.Id, InvalidId); }
public void RevertResizeServerTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.ShutOff); if (ss != null) { Server s = osm.GetServer(ss.Id); //if (s.Status.Name != "SHUTOFF") // os.StopServer(s.Id); if (s.Status != ServerState.VerifyResize) { IEnumerable <Flavor> flavors = osm.ListFlavors(); Flavor flavor1g = flavors.Where <Flavor>(x => x.Name == "g-1gb").First <Flavor>(); Flavor flavor2g = flavors.Where <Flavor>(x => x.Name == "g-2gb").First <Flavor>(); osm.ResizeServer(s.Id, (s.Flavor.Id == flavor1g.Id ? flavor2g.Id : flavor1g.Id), DiskConfiguration.FromName("AUTO")); Trace.WriteLine(String.Format("server requested a resizing : {0}", DateTime.Now)); Trace.WriteLine(String.Format("FlavorId : {0}", s.Flavor.Id)); // wait for request s = osm.ServersProvider.WaitForServerState(s.Id, ServerState.VerifyResize, new[] { ServerState.Error, ServerState.Unknown, ServerState.Suspended }); Trace.WriteLine(String.Format("server status changed to {0} : {1}", s.Status, DateTime.Now)); } // resize bool b = osm.RevertResizeServer(s.Id); Assert.IsTrue(b); Trace.WriteLine(String.Format("server reverted a resizing : {0}", DateTime.Now)); // wait for activate s = osm.ServersProvider.WaitForServerActive(s.Id); Trace.WriteLine(String.Format("server activated : {0}", DateTime.Now)); } }
public void GetInterfaceAttachmentTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); IEnumerable <InterfaceAttachment> interfaces = osm.ListInterfaceAttachments(ss.Id); Assert.IsNotNull(interfaces); Trace.WriteLine(string.Format("InterfaceAttachments count : {0}", interfaces.Count())); if (interfaces.Count() == 0) { osm.AddInterfaceAttachment(ss.Id, GetInterfaceAttachmentIdByTesterName()); } foreach (var _i in interfaces) { InterfaceAttachment i = osm.GetInterfaceAttachment(ss.Id, _i.PortId); Assert.IsNotNull(i); Assert.IsNotNull(i.PortId); Assert.IsNotNull(i.NetId); Assert.IsNotNull(i.MacAddr); Assert.IsNotNull(i.PortState); Trace.WriteLine(string.Format("PortId : {0}, NetId : {1}, MacAddress : {2}, PortState : {3}", i.PortId, i.NetId, i.MacAddr, i.PortState)); } }
public void StartServerTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); Server server = osm.GetServer(ss.Id); // check server status if (server.Status == ServerState.Active && server.VMState == VirtualMachineState.Active) { osm.StopServer(server.Id); // wait for stop WaitForVMState(server.Id, new[] { VirtualMachineState.Stopped }, new[] { VirtualMachineState.Error }); Trace.WriteLine(String.Format("server stopped : {0}", DateTime.Now)); // start server bool b = osm.StartServer(server.Id); Assert.IsTrue(b); Trace.WriteLine(string.Format("server started : {0}", DateTime.Now)); } else { Trace.WriteLine(string.Format("server.Status : {0}", server.Status)); Trace.WriteLine(string.Format("server.VMState : {0}", server.VMState)); } }
public void StopServerTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); Server server = osm.GetServer(ss.Id); // check server status if (server.VMState == VirtualMachineState.Stopped) { if (server.Status != ServerState.Reboot) { osm.StartServer(server.Id); } // wait for activate osm.ServersProvider.WaitForServerActive(server.Id); Trace.WriteLine(String.Format("server activated : {0}", DateTime.Now)); // stop server bool b = osm.StopServer(server.Id); Assert.IsTrue(b); var vmState = server.VMState; Trace.WriteLine(string.Format("server stopped : {0}", DateTime.Now)); } else { Trace.WriteLine(string.Format("server.Status : {0}", server.Status)); Trace.WriteLine(string.Format("server.VMState : {0}", server.VMState)); } }
public void DeleteInterfaceAttachmentTest_InvalidId() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.ShutOff); bool b = osm.DeleteInterfaceAttachment(ss.Id, InvalidId); // 成功が返ります。(202 Accepted) }
public void AddInterfaceAttachmentTest_PortId_Invalid() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); // expect BadServiceRequestException InterfaceAttachment i = osm.AddInterfaceAttachment(ss.Id, InvalidId); }
public void GetVncConsoleTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); VncConsole v = osm.GetVncConsole(ss.Id); Assert.IsNotNull(v); }
public void ListServerSecurityGroupTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); IEnumerable <ServerSecurityGroup> groups = osm.ListServerSecurityGroups(ss.Id); Assert.IsNotNull(groups); }
public void RebuildServerTest_ServerId_Invalid() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); Server server = osm.GetServer(ss.Id); // expect ItemNotFoundException Server rebuiltserver = osm.RebuildServer(InvalidId, server.Image.Id, "newPassword"); }
public void GetServerTest() { var osm = new OpenStackMember(UserName, Password, TenantName); // with tenant SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); Server server = osm.GetServer(ss.Id); Assert.IsTrue(server.Id == ss.Id); Assert.IsTrue(osm.DeleteServer(ss.Id)); }
public void UpdateLBMemberTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); // get server SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); // get ipv4, sometimes server does not have network interface. ServerAddresses addresses = ss.GetDetails().ListAddresses(); Assert.IsNotNull(addresses["default_global"]); Assert.IsTrue(addresses["default_global"].Count() > 0); var ip = addresses["default_global"]. Where(a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) .First <System.Net.IPAddress>(); // create pool string pool_name = GetTesterNameByEnv(); string TokyoLBaas_subnetId = GetSubnetIdByRegion(region: null); int weight = 1; string[] lbMethods = { "ROUND_ROBIN", "LEAST_CONNECTIONS" }; string protocol = "TCP"; foreach (var lbMethod in lbMethods) { // create pool var p = osm.CreatePool(pool_name, TokyoLBaas_subnetId, lbMethod, protocol); try { // create member string address = ip.ToString(); // ip address virtual machine is having. ? string protocolPort = "80"; // a valid value is from 0 to 65535. var member = osm.CreateLBMember(p.Id, address, protocolPort, weight); Assert.IsNotNull(member); try { // update member(toggle adminStateUp) var updatedMember = osm.UpdateLBMember(member.Id, (weight == 1 ? 0 : 1)); Assert.IsNotNull(updatedMember); Assert.IsTrue(updatedMember.Weight != (weight == 1 ? 0 : 1)); } finally { // delete member Assert.IsTrue(osm.DeleteLBMember(member.Id)); } } finally { // Assert.IsTrue(os.DeletePool(p.Id)); } } }
public void DeleteServerTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.ShutOff); if (ss != null) { bool b = osm.DeleteServer(ss.Id); Assert.IsTrue(b); Trace.WriteLine(String.Format("server deleted : {0}", DateTime.Now)); } }
public void DeleteInterfaceAttachmentTest_2Times_Sequencely() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); string attachmentId = GetInterfaceAttachmentIdByTesterName(); bool b = osm.DeleteInterfaceAttachment(ss.Id, attachmentId); Assert.IsTrue(b); Trace.WriteLine(string.Format("interface attachment deleted : {0}", DateTime.Now)); b = osm.DeleteInterfaceAttachment(ss.Id, attachmentId); }
public void ListServersTest() { foreach (var m in TestEnvMembers.Members) { var os = new OpenStackMember(m.UserName, m.Password, m.TenantName); IEnumerable <SimpleServer> servers = os.ListServers(); Assert.IsNotNull(servers); foreach (var s in servers) { Trace.WriteLine(string.Format("serverid : {0}, servername : {1}", s.Id, s.Name)); } } }
public void GetServerVolumeTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.Active); IEnumerable <ServerVolume> servervolumes = osm.ListServerVolumes(ss.Id); //if (s.Status.Name != "SHUTOFF") // os.StopServer(s.Id); Assert.IsNotNull(servervolumes); Trace.WriteLine(String.Format("servervolumes count : {0}", servervolumes.Count())); foreach (var v in servervolumes) { Trace.WriteLine(String.Format("server volume id : {0}", v.Id)); ServerVolume volume = osm.GetServerVolume(ss.Id, v.Id); Assert.IsNotNull(volume); } }
public void ConfirmServerResizedTest_Revert_Without_Resize() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.ShutOff); if (ss != null) { Server s = osm.GetServer(ss.Id); if (s.Status == ServerState.VerifyResize) { osm.RevertResizeServer(s.Id); Trace.WriteLine(String.Format("server reverted a resizing : {0}", DateTime.Now)); // wait for activate s = osm.ServersProvider.WaitForServerActive(s.Id); Trace.WriteLine(String.Format("server activated : {0}", DateTime.Now)); } // expect ServiceConflictException bool b = osm.RevertResizeServer(s.Id); } }
public void ResizeServerTest_same_flavorid() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.ShutOff); if (ss != null) { Server s = osm.GetServer(ss.Id); if (s.Status == ServerState.VerifyResize) { osm.RevertResizeServer(s.Id); Trace.WriteLine(String.Format("server reverted a resizing : {0}", DateTime.Now)); // wait for activate s = osm.ServersProvider.WaitForServerActive(s.Id); Trace.WriteLine(String.Format("server activated : {0}", DateTime.Now)); } // expect BadServiceRequestException bool b = osm.ResizeServer(s.Id, s.Flavor.Id, DiskConfiguration.FromName("AUTO")); Assert.IsTrue(b); } }
public void ResizeServerTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.ShutOff); Server server = osm.GetServer(ss.Id); if (server != null) { if (server.Status == ServerState.VerifyResize) { osm.RevertResizeServer(server.Id); Trace.WriteLine(String.Format("server reverted a resizing : {0}", DateTime.Now)); // wait for activate server = osm.ServersProvider.WaitForServerActive(server.Id); Trace.WriteLine(String.Format("server activated : {0}", DateTime.Now)); } IEnumerable <Flavor> flavors = osm.ListFlavors(); Flavor flavor1g = flavors.Where <Flavor>(x => x.Name == "g-1gb").First <Flavor>(); Flavor flavor2g = flavors.Where <Flavor>(x => x.Name == "g-2gb").First <Flavor>(); bool b; try { b = osm.ResizeServer(server.Id, (server.Flavor.Id == flavor1g.Id ? flavor2g.Id : flavor1g.Id), DiskConfiguration.FromName("AUTO")); Assert.IsTrue(b); Trace.WriteLine(String.Format("server requested a resizing : {0}", DateTime.Now)); Trace.WriteLine(String.Format("FlavorId : {0}", server.Flavor.Id)); // wait for request server = osm.ServersProvider.WaitForServerState(server.Id, ServerState.VerifyResize, new[] { ServerState.Error, ServerState.Unknown, ServerState.Suspended }); Trace.WriteLine(String.Format("server status changed to {0} : {1}", server.Status, DateTime.Now)); } catch (ServiceConflictException sce) { // throwing ServiceConflictException when server is locked is designed. Assert.IsTrue(sce.Message.Contains("locked")); } } }
public void RestartServerTest() { var osm = new OpenStackMember(UserName, Password, TenantName, TenantId); SimpleServer ss = osm.ListServers().FirstOrDefault(s => s.GetDetails().Status == ServerState.ShutOff); Server server = osm.GetServer(ss.Id); // check server status if (server.Status != ServerState.Active) { if (server.Status != ServerState.Reboot) { osm.StartServer(server.Id); } // wait for activate osm.ServersProvider.WaitForServerActive(server.Id); Trace.WriteLine(String.Format("server activated : {0}", DateTime.Now)); } bool b = server.SoftReboot(); Assert.IsTrue(b); Trace.WriteLine(string.Format("server restarted : {0}", DateTime.Now)); }
public void CreateServerTest_5times() { OpenStackMember os = null; NewServer server = null; var serverIds = new List <string>(); try { os = new OpenStackMember(UserName, Password, TenantName, TenantId); var image = os.ListImages().First(); for (int cnt = 1; cnt <= 15; cnt++) { IEnumerable <SimpleServer> servers = os.ListServers(); var names = servers.GroupBy(s => s.Name, (key, g) => key); string[] data = Enumerable.Range(1, 100).Select(i => string.Format("{0}_{1}", TesterName, i)).ToArray <string>(); string serverName = (from b in data where !names.Contains <string>(b) select b).First(); server = os.CreateServer(serverName, image.Id, GetFlavorByName("g-1gb").Id, "D$fjhg5422mnM-"); serverIds.Add(server.Id); Trace.WriteLine(String.Format("server creation transferred : {0}", DateTime.Now)); Assert.IsNotNull(server); Assert.IsNotNull(server.AdminPassword); Trace.WriteLine(string.Format("ServerName : {0}", serverName)); Trace.WriteLine(string.Format("AdminPassword : {0}", server.AdminPassword)); } } finally { foreach (var serverId in serverIds) { bool bDelete = os.DeleteServer(serverId); Assert.IsTrue(bDelete); Trace.WriteLine(String.Format("server deletion transferred : {0}", DateTime.Now)); os.ServersProvider.WaitForServerDeleted(serverId); Trace.WriteLine(String.Format("server deleted : {0}", DateTime.Now)); } } }
public void CreateServerTest() { var os = new OpenStackMember(UserName, Password, TenantName, TenantId); var image = os.ListImages().First(); // decide server name which is not duplicated. IEnumerable <SimpleServer> servers = os.ListServers(); var names = servers.GroupBy(s => s.Name, (key, g) => key); string[] data = Enumerable.Range(1, 100).Select(i => string.Format("{0}_{1}", TesterName, i)).ToArray <string>(); string serverName = (from b in data where !names.Contains <string>(b) select b).First(); // create server // the name tag must not contain space NewServer server = os.CreateServer(serverName, image.Id, GetFlavorByName("g-1gb").Id, "S5df!Afdas%'Zt", keyname: null, nametag: "test_nametag", networks: null); Trace.WriteLine(String.Format("server creation transferred : {0}", DateTime.Now)); Assert.IsNotNull(server); Assert.IsNotNull(server.AdminPassword); Trace.WriteLine(string.Format("ServerName : {0}", serverName)); Trace.WriteLine(string.Format("AdminPassword : {0}", server.AdminPassword)); // wait for activate os.ServersProvider.WaitForServerActive(server.Id); Trace.WriteLine(String.Format("server activated : {0}", DateTime.Now)); bool bDelete = os.DeleteServer(server.Id); Assert.IsTrue(bDelete); Trace.WriteLine(String.Format("server deletion transferred : {0}", DateTime.Now)); // wait for delete os.ServersProvider.WaitForServerDeleted(server.Id); Trace.WriteLine(String.Format("server deleted : {0}", DateTime.Now)); }