class TestDisk(unittest.TestCase): def setUp(self): self.root = Skytap() """configurations = Configurations(username, password)""" self.configurations = self.root.configurations() template = self.root.templates()["294385"] self.assertTrue(template is not None, "Unable to get template 294385") self.config1 = template.create_configuration() self.config1.wait_for() def test_createNewDisk(self): vm1 = self.config1.vms().values()[0] self.assertEqual(len(vm1.hardware().disks()), 1, "Expected only 1 initial disk in vm") vm1.hardware().addDisk(8192) self.config1.wait_for() vm1.refresh() self.assertEqual(len(vm1.hardware().disks()), 2, "Expected 2 disks in vm") def test_DeleteDisk(self): vm1 = self.config1.vms().values()[0] self.assertEqual(len(vm1.hardware().disks()), 1, "Expected only 1 initial disk in vm") vm1.hardware().addDisk(8192) self.config1.wait_for() vm1.refresh() self.assertEqual(len(vm1.hardware().disks()), 2, "Expected 2 disks in vm") vm1.hardware().disks()[1].delete() self.config1.wait_for() vm1.refresh() self.assertEqual(len(vm1.hardware().disks()), 1, "Expected 1 disks in vm") def tearDown(self): self.config1.delete()
class TestTunnels(unittest.TestCase): def setUp(self): self.root = Skytap() self.configurations = self.root.configurations() template = self.root.templates()['294385'] self.configuration1 = template.create_configuration() self.configuration1.wait_for() self.configuration1.name = "Source Config" self.configuration2 = template.create_configuration() self.configuration2.wait_for() self.configuration2.name = "Target Config" def tearDown(self): self.configuration1.delete() self.configuration2.delete() def test_createAndDeleteTunnel(self): self.assertTrue(len(self.configurations) > 0, "No configurations for this user") inVar = False n1 = self.configuration1.networks().values()[0] n2 = self.configuration2.networks().values()[0] n2.subnet_addr = '10.0.1.0' n2.tunnelable = True n2.refresh() time.sleep(30) r = n1.create_tunnel(n2.uid) n1.refresh() tunnels = n1.tunnels() self.assertTrue(len(tunnels) > 0, "No tunnels for this configuration") for r in tunnels: self.assertTrue(isinstance(r, Tunnel), "Didn't traverse any tunnels") inVar = True self.assertTrue(inVar, "Didn't traverse any tunnels")
class TestTunnels(unittest.TestCase): def setUp(self): self.root = Skytap() self.configurations = self.root.configurations() template = self.root.templates()['294385'] self.configuration1 = template.create_configuration() self.configuration1.wait_for() self.configuration1.name = "Source Config" self.configuration2 = template.create_configuration() self.configuration2.wait_for() self.configuration2.name = "Target Config" def tearDown(self): self.configuration1.delete() self.configuration2.delete() def test_createAndDeleteTunnel(self): self.assertTrue( len(self.configurations) > 0, "No configurations for this user") inVar = False n1 = self.configuration1.networks().values()[0] n2 = self.configuration2.networks().values()[0] n2.subnet_addr = '10.0.1.0' n2.tunnelable = True n2.refresh() time.sleep(30) r = n1.create_tunnel(n2.uid) n1.refresh() tunnels = n1.tunnels() self.assertTrue(len(tunnels) > 0, "No tunnels for this configuration") for r in tunnels: self.assertTrue(isinstance(r, Tunnel), "Didn't traverse any tunnels") inVar = True self.assertTrue(inVar, "Didn't traverse any tunnels")
def setUpModule(): global root, configurations, config root = Skytap() """configurations = Configurations(username, password)""" configurations = root.configurations() template = root.templates()['294385'] config = template.create_configuration() config.wait_for() config.name = 'test config'
def setUpModule(): global root, configurations, config root = Skytap() """configurations = Configurations(username, password)""" configurations = root.configurations() template = root.templates()['294385'] config = template.create_configuration() config.wait_for() config.name = 'test config'
class SaveConfigurationAsTemplate(unittest.TestCase): def setUp(self): self.root = Skytap() self.configurations = self.root.configurations() self.templates = self.root.templates() def test_saveConfigurationAsTemplate(self): print('in saveConfigurationAsTemplate(%s)' % (self)) configurationName = sys.argv[1] self.assertTrue( len(configurationName) > 1, "Configuration name must be passed in") templateName = configurationName + " - Running Components" """ Delete the template """ print("Delete the template") templates = self.templates.get_by_name(templateName) if len(templates) > 0: for template in templates: print("Deleting template %s" % (template)) template.delete() """ Save the existing configuration as a template """ print("Save the existing configuration as a template") self.configurations.refresh() configs = self.configurations.get_by_name(configurationName) self.assertTrue( len(configs) == 1, "Should only be one '%s' configuration. Found {1} configuration(s)" % (configurationName, len(configs))) config = configs[0] template = config.createTemplate() self.assertTrue(template is not None, "Unable to create new template") template.name = templateName self.templates.refresh() templates = self.templates.get_by_name(templateName) self.assertTrue( len(templates) == 1, "Should only be one '%s' template. Found {1} template(s)" % (templateName, len(templates))) """ Wait for the configuration to not be busy """ print("Wait for the configuration to not be busy") iterations = 0 self.configurations.refresh() config = self.configurations.getByName(configurationName)[0] while ((config.runstate == 'busy') & (iterations < 10)): print("'%s' %s. Sleep for 30 seconds" % (configurationName, config.runstate)) time.sleep(30) self.configurations.refresh() config = self.configurations.getByName(configurationName)[0] iterations += 1
class DeleteConfiguration(unittest.TestCase): def setUp(self): self.root = Skytap() self.configurations = self.root.configurations() def test_deleteConfiguration(self): print("in test_deleteConfiguration(%s)" % (self)) configurationName = sys.argv[1] self.assertTrue(len(configurationName) > 0, "Name of configuration must be passed in") """ Delete the existing configuration """ print("Delete the configuration") configs = self.configurations.get_by_name(configurationName) if len(configs) > 0: for config in configs: print("Deleting configuration %s" % (config)) config.delete()
class DeleteConfiguration(unittest.TestCase): def setUp(self): self.root = Skytap() self.configurations = self.root.configurations() def test_deleteConfiguration(self): print('in test_deleteConfiguration(%s)' % (self)) configurationName = sys.argv[1] self.assertTrue( len(configurationName) > 0, "Name of configuration must be passed in") """ Delete the existing configuration """ print("Delete the configuration") configs = self.configurations.get_by_name(configurationName) if len(configs) > 0: for config in configs: print("Deleting configuration %s" % (config)) config.delete()
class SaveConfigurationAsTemplate(unittest.TestCase): def setUp(self): self.root = Skytap() self.configurations = self.root.configurations() self.templates = self.root.templates() def test_saveConfigurationAsTemplate(self): print('in saveConfigurationAsTemplate(%s)' % (self)) configurationName = sys.argv[1] self.assertTrue(len(configurationName) > 1, "Configuration name must be passed in") templateName = configurationName + " - Running Components" """ Delete the template """ print("Delete the template") templates = self.templates.get_by_name(templateName) if len(templates) > 0: for template in templates: print("Deleting template %s" % (template)) template.delete() """ Save the existing configuration as a template """ print("Save the existing configuration as a template") self.configurations.refresh() configs = self.configurations.get_by_name(configurationName) self.assertTrue(len(configs) == 1, "Should only be one '%s' configuration. Found {1} configuration(s)" % (configurationName, len(configs))) config = configs[0] template = config.createTemplate() self.assertTrue(template is not None, "Unable to create new template") template.name = templateName self.templates.refresh() templates = self.templates.get_by_name(templateName) self.assertTrue(len(templates) == 1, "Should only be one '%s' template. Found {1} template(s)" % (templateName, len(templates))) """ Wait for the configuration to not be busy """ print("Wait for the configuration to not be busy") iterations = 0 self.configurations.refresh() config = self.configurations.getByName(configurationName)[0] while ((config.runstate == 'busy') & (iterations < 10)): print("'%s' %s. Sleep for 30 seconds" % (configurationName, config.runstate)) time.sleep(30) self.configurations.refresh() config = self.configurations.getByName(configurationName)[0] iterations += 1
class TestDisk(unittest.TestCase): def setUp(self): self.root = Skytap() """configurations = Configurations(username, password)""" self.configurations = self.root.configurations() template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") self.config1 = template.create_configuration() self.config1.wait_for() def test_createNewDisk(self): vm1 = self.config1.vms().values()[0] self.assertEqual(len(vm1.hardware().disks()), 1, "Expected only 1 initial disk in vm") vm1.hardware().addDisk(8192) self.config1.wait_for() vm1.refresh() self.assertEqual(len(vm1.hardware().disks()), 2, "Expected 2 disks in vm") def test_DeleteDisk(self): vm1 = self.config1.vms().values()[0] self.assertEqual(len(vm1.hardware().disks()), 1, "Expected only 1 initial disk in vm") vm1.hardware().addDisk(8192) self.config1.wait_for() vm1.refresh() self.assertEqual(len(vm1.hardware().disks()), 2, "Expected 2 disks in vm") vm1.hardware().disks()[1].delete() self.config1.wait_for() vm1.refresh() self.assertEqual(len(vm1.hardware().disks()), 1, "Expected 1 disks in vm") def tearDown(self): self.config1.delete()
class TestConfigurations(unittest.TestCase): def setUp(self): self.root = Skytap() """configurations = Configurations(username, password)""" self.configurations = self.root.configurations() template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") config = template.create_configuration() config.wait_for() config.name = 'test config' def test_lookupNotExist(self): result_list = self.configurations['123456'] self.assertTrue(result_list is None, "Lookup of config that doesn't exist should return None") def test_getAllConfigurations(self): self.assertTrue(len(self.configurations) > 0, "No configurations for this user") inVar = False for r in self.configurations.values(): self.assertTrue(isinstance(r, Configuration), "Didn't traverse any configurations") inVar = True self.assertTrue(inVar, "Didn't traverse any configurations") def test_getConfigurationByName(self): result_list = self.configurations.get_by_name('test config') self.assertTrue(len(result_list) == 1, "Received %s configs from lookup of 'test config'" % (len(result_list))) count = 0 for r in result_list: self.assertTrue(isinstance(r, Configuration), "Item is not a configuration") count += 1 self.assertTrue(count == 1, "Didn't traverse any configurations") def test_startConfiguration(self): template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") config1 = template.create_configuration() config1.wait_for() newState = 'running' config1.runstate = newState self.assertTrue( config1.runstate != newState, "Verify state doesn't change immediately") config1.wait_for() config2 = self.configurations[config1.uid] self.assertTrue(config2.runstate == newState, "Configuration state not changed to %s" % (newState)) config1.delete() def test_createAndDeleteConfiguration(self): template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") config = template.create_configuration() uid = config.uid self.assertTrue(config is not None, "Unable to create new config") c1 = self.configurations[uid] self.assertTrue(c1 is not None and c1.uid == uid, "Unable to find config for delete test") c1.delete() time.sleep(60) self.configurations.refresh() c2 = self.configurations[uid] self.assertTrue(c2 is None, "Deleted config is still searchable") def test_createConfigurationAndMergeTemplate(self): template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") config = template.create_configuration() self.assertEqual(len(config.vms().values()), 1, "Config doesn't have right number of vms before merging template in") self.assertTrue(config is not None, "Unable to create new config") config.wait_for() config.merge_template(template.uid) config.wait_for() self.assertEqual(len(config.vms().values()), 2, "Config doesn't have right number of vms after merging template in") config.delete() def tearDown(self): result_list = self.configurations.get_by_name('test config') if(len(result_list) == 1): result_list[0].delete()