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")
class TestTemplates(unittest.TestCase): def setUp(self): self.root = Skytap() def test_getAllTemplates(self): templates = self.root.templates() self.assertTrue(isinstance(templates.alldata(), list), "Templates.alldata didn't return a list") for i in templates.alldata(): self.assertTrue( isinstance(i, dict), "Templates.alldata didn't return a list of dict %s" % (i)) def test_doesntExistLookup(self): result = self.root.templates()['1234'] self.assertTrue(result is None, "Lookup incorrectly returned result %s" % (result)) def test_getOneTemplate(self): result = self.root.templates().values()[0] self.assertTrue(isinstance(result, Template), "Lookup didn't return a template") self.assertTrue(isinstance(result.alldata(), dict), "Template.alldata didn't return a dict") def test_lookupTemplateByName(self): resultList = self.root.templates().get_by_name('CentOS 6.3 x64') self.assertTrue( len(resultList) == 2, "Found %s templates instead of the expected 1." % (len(resultList))) self.assertTrue(isinstance(resultList[0], Template), "Lookup didn't return a template") self.assertTrue(isinstance(resultList[0].alldata(), dict), "Template.alldata didn't return a dict")
def setUp(self): self.root = Skytap() """configurations = Configurations(username, password)""" template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") self.config = template.create_configuration() self.config.wait_for()
def setUp(self): self.root = Skytap() template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") self.config = template.create_configuration() self.config.wait_for() self.template = self.config.create_template() self.template.wait_for()
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 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"
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 TestVMs(unittest.TestCase): def setUp(self): self.root = Skytap() """configurations = Configurations(username, password)""" template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") self.config = template.create_configuration() self.config.wait_for() def test_vms_exist(self): vms = self.config.vms().values() self.assertTrue(len(vms) > 0, "Configuration has no VMs") def test_vm_labels(self): vm = self.config.vms().values()[0] labels = vm.labels() label_count = len(labels.values()) labels.create_label('my_text', 'ApplicationTag') vm.refresh() labels = vm.labels() self.assertEqual(len(labels.values()), label_count + 1, "Wrong number of labels after creating a new label") def test_vm_notes(self): vm = self.config.vms().values()[0] notes = vm.notes() note_count = len(notes.values()) notes.create_note('my_note') vm.refresh() notes = vm.notes() self.assertEqual(len(notes.values()), note_count + 1, "Wrong number of notes after creating a new label") def tearDown(self): self.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 TestProjects(unittest.TestCase): def setUp(self): self.root = Skytap() template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") self.config = template.create_configuration() self.config.wait_for() self.template = self.config.create_template() self.template.wait_for() def test_createDeleteProject(self): new_project = self.root.projects().create_project('test_project_1') self.assertTrue(isinstance(new_project, Project)) new_project.delete() def test_assignTemplate(self): new_project = self.root.projects().create_project('test_project_2') self.template.add_to_project(new_project) templates = new_project.templates() temp = [x for x in templates if x.uid == self.template.uid] self.assertEquals(len(temp), 1) self.assertTrue(isinstance(temp[0], Template)) new_project.delete() def test_assignConfiguration(self): new_project = self.root.projects().create_project('test_project_3') self.config.add_to_project(new_project) configurations = new_project.configurations() temp = [x for x in configurations if x.uid == self.config.uid] self.assertEquals(len(temp), 1) self.assertTrue(isinstance(temp[0], Configuration)) new_project.delete() def tearDown(self): self.config.delete() self.template.delete()
class TestProjects(unittest.TestCase): def setUp(self): self.root = Skytap() template = self.root.templates()['294385'] self.assertTrue(template is not None, "Unable to get template 294385") self.config = template.create_configuration() self.config.wait_for() self.template = self.config.create_template() self.template.wait_for() def test_createDeleteProject(self): new_project = self.root.projects().create_project('test_project_1') self.assertTrue(isinstance(new_project, Project)) new_project.delete() def test_assignTemplate(self): new_project = self.root.projects().create_project('test_project_2') self.template.add_to_project(new_project) templates = new_project.templates() temp = filter(lambda x: x.uid == self.template.uid, templates) self.assertEquals(len(temp), 1) self.assertTrue(isinstance(temp[0], Template)) new_project.delete() def test_assignConfiguration(self): new_project = self.root.projects().create_project('test_project_3') self.config.add_to_project(new_project) configurations = new_project.configurations() temp = filter(lambda x: x.uid == self.config.uid, configurations) self.assertEquals(len(temp), 1) self.assertTrue(isinstance(temp[0], Configuration)) new_project.delete() def tearDown(self): self.config.delete() self.template.delete()
class TestTemplates(unittest.TestCase): def setUp(self): self.root = Skytap() def test_getAllTemplates(self): templates = self.root.templates() self.assertTrue(isinstance(templates.alldata(), list), "Templates.alldata didn't return a list") for i in templates.alldata(): self.assertTrue(isinstance(i, dict), "Templates.alldata didn't return a list of dict %s" % (i)) def test_doesntExistLookup(self): result = self.root.templates()['1234'] self.assertTrue(result is None, "Lookup incorrectly returned result %s" % (result)) def test_getOneTemplate(self): result = self.root.templates().values()[0] self.assertTrue(isinstance(result, Template), "Lookup didn't return a template") self.assertTrue(isinstance(result.alldata(), dict), "Template.alldata didn't return a dict") def test_lookupTemplateByName(self): resultList = self.root.templates().get_by_name('CentOS 6.3 x64') self.assertTrue(len(resultList) == 2,"Found %s templates instead of the expected 1." % (len(resultList))) self.assertTrue(isinstance(resultList[0], Template), "Lookup didn't return a template") self.assertTrue(isinstance(resultList[0].alldata(), dict), "Template.alldata didn't return a dict")
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()
def testAPI(): obj = Skytap() objs = queue.Queue() objs.put((obj, "")) exploredTypes = ignoreTypes[:] logger = logging.getLogger('dxskytap.test') while not objs.empty(): (o, p) = objs.get() logger.info(" **********************************") logger.info(" * OBJECT: %s" % (type(o).__name__)) logger.info(" **********************************") for attr in dir(o): if not pattern.match(attr) and not attr in ignoreAttrs: v = getattr(o, attr, None) if callable(v): handleFunction(v, p, objs, exploredTypes, logger) else: logger.info("GET: %s" % attr) handleObject(v, p, objs, exploredTypes)
class TestReports(unittest.TestCase): def setUp(self): self.root = Skytap() self.reports = self.root.reports() def test_generateReadReport(self): midnight = datetime.datetime.combine(datetime.date.today(), datetime.time.min) sdate = midnight - datetime.timedelta(days=2) edate = midnight - datetime.timedelta(days=1) rpt = self.reports.generate_usage_report(sdate, edate, region='US-East', group_by='user', aggregate_by='day') rpt.wait_for(30, 30) reader = rpt.get_reader() count = 0 maxlen = 0 for line in reader: if len(line) > maxlen: maxlen = len(line) count = count + 1 self.assertGreater(count, 0, 'Report contains zero rows') self.assertGreater(maxlen, 0, 'Report rows all blank') def tearDown(self): pass
def setUp(self): self.root = Skytap() self.configurations = self.root.configurations() self.templates = self.root.templates()
def setUp(self): self.root = Skytap() """configurations = Configurations(username, password)""" self.configurations = self.root.configurations() self.template = self.root.templates()['294385'] self.assertTrue(self.template is not None, "Unable to get template 294385")
def setUp(self): self.root = Skytap()
def setUp(self): self.root = Skytap() self.reports = self.root.reports()
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()