def test_tags_del(self): """ Testing DELETE:api/2.0/tags/:tagName """ LOG.info("Deleting tag that was created in" " Testing POST:/api/2.0/tags/ ") Api().nodes_get_all() nodes = self.__get_data() for n in nodes: if n.get('type') == 'compute': Api().delete_tag(tag_name=n.get('id')) rsp = self.__client.last_response assert_equal(204, rsp.status, message=rsp.reason) Api().get_all_tags() rsp = self.__client.last_response updated_tags = self.__get_data() assert_equal(200, rsp.status, message=rsp.reason) assert_equal([], updated_tags, message='Tags were not deleted successfully')
def test_node_tags_patch(self): """ Testing PATCH:/api/2.0/nodes/:id/tags """ codes = [] Api().nodes_get_all() rsp = self.__client.last_response nodes = loads(rsp.data) codes.append(rsp) for n in nodes: Api().nodes_patch_tag_by_id(identifier=n.get('id'), body=self.__test_tags) rsp = self.__client.last_response codes.append(rsp) for c in codes: assert_equal(200, c.status, message=c.reason) assert_raises(rest.ApiException, Api().nodes_patch_tag_by_id, 'fooey', body=self.__test_tags)
def __get_workflow_status(self, id): Api().nodes_get_active_workflow_by_id(identifier=id) status = self.__client.last_response.status if status == 200: data = self.__get_data() if data: status = data.get('_status') assert_is_not_none(status) return status
def post_lookup_negativeTesting(self): """ Negative Testing POST / """ #Validate that a POST for a lookup with same id as an existing one gets rejected try: Api().lookups_post(self.lookup) except ApiException as e: assert_equal(400, e.status, message = 'status should be 400') except (TypeError, ValueError) as e: assert(e.message)
def delete_lookup(self): """ Testing DELETE /:id """ #Validate that the lookup is there before it is deleted Api().lookups_get_by_id(self.id) rsp = self.__client.last_response assert_equal(200, rsp.status, message=rsp.reason) #delete the lookup LOG.info("The lookup ID to be deleted is "+ self.id) Api().lookups_del_by_id(self.id) rsp = self.__client.last_response assert_equal(200, rsp.status, message=rsp.reason) #Validate that the lookup has been deleted and the returned value is an empty list try: Api().lookups_get_by_id(self.id) except Exception,e: assert_equal(404,e.status)
def test_negative_workflows_id_get(self): # """ Negative Testing GET:/workflows/identifier""" try: Api().workflows_get_by_instance_id("WrongIdentifier") self.assertEqual(404, self.__get_result(), msg='status should be 404. No exception raised') except ApiException as e: self.assertEqual(404, e.status, msg='Expected 404 status, received {}'.format(e.status)) except (TypeError, ValueError) as e: assert(e.message)
def test_delete_skus(self): # """Test DELETE:api/2.0/skus/:identifier""" logs.info(' Deleting SKU %s', self.__class__.__sku_id) Api().skus_id_delete(identifier=self.__class__.__sku_id) result = self.__client.last_response self.assertEqual(204, result.status, msg=result.reason) # Check if sku was deleted try: Api().skus_id_get(identifier=self.__class__.__sku_id) except ApiException as e: self.assertEqual(404, e.status, msg='Expected 404, received {}'.format(e.status)) # Check delete of invalid id try: Api().skus_id_delete(identifier='does_not_exist') except ApiException as e: self.assertEqual(404, e.status, msg='Expected 404, received {}'.format(e.status))
def test_node_delete(self): # Testing DELETE:/api/2.0/nodes/:id codes = [] Api().nodes_get_all() nodes = self.__get_data() test_names = [t.get('name') for t in self.__test_nodes] for n in nodes: name = n.get('name') if name in test_names: uuid = n.get('id') logs.info(' Deleting node %s (name=%s)', uuid, name) Api().nodes_del_by_id(identifier=uuid) codes.append(self.__client.last_response) self.assertNotEqual(0, len(codes), msg='Delete node list empty, should contain test nodes!') for c in codes: self.assertEqual(204, c.status, msg=c.reason) self.assertRaises(ApiException, Api().nodes_del_by_id, 'fooey')
def check_compute_count(self): Api().nodes_get_all() nodes = loads(self.__client.last_response.data) count = 0 for n in nodes: type = n.get('type') if type == 'compute': count += 1 return count
def test_create_user(self): """ Testing create new user """ newuser = { 'username': '******', 'password': '******', 'role': 'Administrator' } Api().add_user(body=newuser) Api().list_users() users = self.__get_data() LOG.debug(users, json=True) found = False for user in users: if newuser.get('username') == user.get('username'): found = True assert_equal(newuser.get('role'), user.get('role')) if not found: fail(message='newly created user was not found')
def test_node_id(self): # Testing GET:/api/2.0/nodes/:id Api().nodes_get_all() nodes = self.__get_data() logs.debug(json.dumps(nodes, indent=4)) codes = [] for n in nodes: logs.info(" Node: %s %s %s", n.get('id'), n.get('type'), n.get('name')) logs.debug(json.dumps(n, indent=4)) if n.get('type') == 'compute': uuid = n.get('id') Api().nodes_get_by_id(identifier=uuid) rsp = self.__client.last_response codes.append(rsp) self.assertNotEqual(0, len(codes), msg='Failed to find compute node Ids') for c in codes: self.assertEqual(200, c.status, msg=c.reason) self.assertRaises(ApiException, Api().nodes_get_by_id, 'fooey')
def test_node_id_obm(self): """ Testing GET:/api/2.0/nodes/:id/obm """ Api().nodes_get_all() nodes = self.__get_data() LOG.debug(nodes,json=True) codes = [] for n in nodes: if n.get('name') == 'test_compute_node': uuid = n.get('id') Api().nodes_get_obm_by_id(identifier=uuid) rsp = self.__client.last_response LOG.info('OBM setting for node ID {0} is {1}'.format(uuid, rsp.data)) codes.append(rsp) assert_not_equal(0, len(codes), message='Failed to find compute node Ids') for c in codes: assert_equal(200, c.status, message=c.reason) assert_raises(rest.ApiException, Api().nodes_get_obm_by_id, 'fooey')
def test_workflows_graphs_get(self): # """Testing GET:/workflows/graphs""" Api().workflows_get_graphs() self.assertEqual(200, self.__client.last_response.status) resp = loads(self.__client.last_response.data) logs.debug_6(" Workflow graphs: %s", dumps(resp, indent=4)) self.assertNotEqual(0, len(loads(self.__client.last_response.data)), msg='Workflows list was empty!')
def test_workflows_post(self): # """Testing POST:/workflows""" Api().workflows_post(body={"name": 'Graph.noop-example'}) self.assertEqual(201, self.__client.last_response.status) rawj = loads(self.__client.last_response.data) instance_id = rawj.get('instanceId') self.assertIsNotNone(instance_id) self.assertEqual('Graph.noop-example', str(rawj['definition'].get('injectableName')))
def test_tags(self): # """ Testing GET:/api/2.0/tags """ Api().nodes_get_all() nodes = self.__get_data() tagsArray = [] for n in nodes: if n.get('type') == 'compute': tagsWithRules = self.__create_tag_rule(n.get('id')) self.assertNotEqual(len(tagsWithRules), 0, "Failed to create tag rules") tagsArray.append(tagsWithRules) Api().get_all_tags() rsp = self.__client.last_response updated_tags = self.__get_data() self.assertEqual(200, rsp.status, msg=rsp.reason) for i in xrange(len(updated_tags)): self.assertEqual(updated_tags[i]['rules'][0]['path'], 'dmi.System Information.Manufacturer', msg='Tag {} has incorrect path: {}'.format(updated_tags[i], updated_tags[i]['rules'][0]['path']))
def check_compute_count(self): Api().nodes_get_all() nodes = self.__get_data() count = 0 for n in nodes: type = n.get('type') if type == 'compute': count += 1 return count
def test_18_node_put_obm_invalid_node_id(self): # Testing that PUT:/api/2.0/:id/obm returns 404 with invalid node ID Api().nodes_get_all() rsp = self.__client.last_response nodes = loads(rsp.data) self.assertEqual(200, rsp.status, msg=rsp.status) for n in nodes: if n.get('type') == 'compute': try: Api().nodes_put_obms_by_node_id(identifier='invalid_ID', body=self.__test_obm) self.fail(msg='did not raise exception') except rest.ApiException as e: self.assertEqual( 404, e.status, msg='unexpected response {0}, expected 404'.format( e.status))
def test_node_delete(self): """ Testing DELETE:/api/2.0/nodes/:id """ codes = [] test_names = [] Api().nodes_get_all() nodes = self.__get_data() test_names = [t.get('name') for t in self.__test_nodes] for n in nodes: name = n.get('name') if name in test_names: uuid = n.get('id') LOG.info('Deleting node {0} (name={1})'.format(uuid, name)) Api().nodes_del_by_id(identifier=uuid) codes.append(self.__client.last_response) assert_not_equal(0, len(codes), message='Delete node list empty!') for c in codes: assert_equal(204, c.status, message=c.reason) assert_raises(rest.ApiException, Api().nodes_del_by_id, 'fooey')
def test_node_id(self): """ Testing GET:/api/2.0/nodes/:id """ Api().nodes_get_all() nodes = self.__get_data() LOG.debug(nodes, json=True) codes = [] for n in nodes: LOG.info(n, json=True) if n.get('type') == 'compute': uuid = n.get('id') Api().nodes_get_by_id(identifier=uuid) rsp = self.__client.last_response codes.append(rsp) assert_not_equal(0, len(codes), message='Failed to find compute node Ids') for c in codes: assert_equal(200, c.status, message=c.reason) assert_raises(rest.ApiException, Api().nodes_get_by_id, 'fooey')
def test_tags(self): """ Testing GET:/api/2.0/tags """ Api().nodes_get_all() nodes = self.__get_data() tagsArray = [] for n in nodes: if n.get('type') == 'compute': tagsWithRules = self.__create_tag_rule(n.get('id')) assert_not_equal(len(tagsWithRules), 0, "Failed to create tag rules") tagsArray.append(tagsWithRules) Api().get_all_tags() rsp = self.__client.last_response updated_tags = self.__get_data() assert_equal(200, rsp.status, message=rsp.reason) for i in xrange(len(updated_tags)): assert_equal(updated_tags[i]['rules'][0]['path'], 'dmi.System Information.Manufacturer', message='Could not find the tag')
def __get_compute_nodes(self): Api().nodes_get_all() nodes = self.__get_data() compute_nodes = [] for n in nodes: type = n.get('type') if type == 'compute': compute_nodes.append(n) LOG.info('compute nodes count {0}'.format(len(compute_nodes))) return sorted(compute_nodes, key=lambda k: k['id'])
def test_03_node_id(self): # Testing GET:/api/2.0/nodes/:id Api().nodes_get_all() nodes = self.__get_data() LOG.info(nodes,json=True) codes = [] for n in nodes: LOG.info(n,json=True) if fit_common.VERBOSITY >= 2: print ("Info: nodeid {} {} {}".format(n.get('id'),n.get('type'),n.get('name'))) if n.get('type') == 'compute': uuid = n.get('id') Api().nodes_get_by_id(identifier=uuid) rsp = self.__client.last_response codes.append(rsp) self.assertNotEqual(0, len(codes), msg='Failed to find compute node Ids') for c in codes: self.assertEqual(200, c.status, msg=c.reason) self.assertRaises(rest.ApiException, Api().nodes_get_by_id, 'fooey')
def test_check_lookups_query(self): # """ Testing GET:/lookups?q=term """ Api().nodes_get_all() nodes = loads(self.__client.last_response.data) self.assertNotEqual(0, len(nodes), msg='Node list was empty!') Api().obms_get() obms = loads(self.__client.last_response.data) logs.debug("OBM get data: %s", dumps(obms, indent=4)) hosts = [] for o in obms: hosts.append(o.get('config').get('host')) self.assertNotEqual(0, len(hosts), msg='No OBM hosts were found!') logs.debug("Hosts: %s", dumps(hosts, indent=4)) for host in hosts: logs.debug("Looking up host: %s", host) Api().lookups_get(q=host) rsp = self.__client.last_response self.assertEqual(200, rsp.status, msg=rsp.reason) self.assertNotEqual(0, len(rsp.data))
def test_node_get_obm_by_node_id(self): """Testing GET:/api/2.0/:id/obm""" Api().nodes_get_all() rsp = self.__client.last_response nodes = loads(rsp.data) assert_equal(200, rsp.status, message=rsp.status) for n in nodes: LOG.info(n, json=True) Api().nodes_get_obms_by_node_id(identifier=n.get('id')) LOG.info('getting OBMs for node {0}'.format(n.get('id'))) rsp = self.__client.last_response assert_equal(200, rsp.status, message=rsp.status) obms = loads(rsp.data) assert_not_equal(0, len(obms), message='OBMs list was empty!') for obm in obms: id = obm.get('id') Api().obms_delete_by_id(identifier=id) rsp = self.__client.last_response assert_equal(204, rsp.status, message=rsp.status)
def test_pollers_patch(self): # """Test PATCH:api/2.0/pollers/:identifier""" patch_data = {"pollInterval": 5000} for poller in self.__class__.created_pollers: Api().pollers_patch(poller['id'], patch_data) result = self.__client.last_response data = loads(self.__client.last_response.data) self.assertEqual(200, result.status, msg=result.reason) self.assertEqual(5000, data['pollInterval']) poller = data try: Api().pollers_patch('does_not_exist', {}) except ApiException as e: self.assertEqual(404, e.status, msg='Expected 404 status, received {}'.format( e.status))
def test_04_node_create(self): # Testing POST:/api/2.0/nodes/ # This test uses the fake set of nodes __test_nodes for n in self.__test_nodes: LOG.info('Creating node (name={0})'.format(n.get('name'))) if fit_common.VERBOSITY >= 2: print("Creating node (name={0})".format(n.get('name'))) Api().nodes_post(identifiers=n) rsp = self.__client.last_response self.assertEqual(201, rsp.status, msg=rsp.reason)
def test_02_nodes(self): # Testing GET:/api/2.0/nodes Api().nodes_get_all() nodes = self.__get_data() LOG.info(nodes, json=True) if fit_common.VERBOSITY >= 2: for node in nodes: print "Node: {} {} {}".format(node.get('id'), node.get('type'), node.get('name')) self.assertNotEqual(0, len(nodes), msg='Node list was empty!')
def test_node_get_obm_invalid_node_id(self): # Testing that PUT:/api/2.0/:id/obm returns 404 with invalid node ID try: Api().nodes_get_obms_by_node_id(identifier='invalid_ID') self.fail(msg='did not raise exception') except ApiException as e: self.assertEqual( 404, e.status, msg='unexpected response {0}, expected 404'.format(e.status))
def __get_sku_id_from_name(self, name): Api().skus_get() skus = self.__get_data() for n in skus: sku_name = n.get('name') logs.info_6('Checking sku name %s', sku_name) self.assertIsNotNone(sku_name) if sku_name == name: return n.get('id') return None
def test_node_tags_masterDel(self): # Testing DELETE:api/2.0/nodes/tags/:tagName # negative test: This workflow calls the test_node_tags_patch test above to # get tags put back on the nodes, then verifies trying to delete an non-existing # tag id doesn't cause a failure, then it deletes all the tags that were created codes = [] self.test_node_tags_patch() t = 'tag3' logs.info(" Check to make sure invalid tag is not deleted") Api().nodes_master_del_tag_by_id(tag_name=t) rsp = self.__client.last_response codes.append(rsp) logs.info(" Test to check valid tags are deleted") for t in self.__test_tags.get('tags'): Api().nodes_master_del_tag_by_id(tag_name=t) rsp = self.__client.last_response codes.append(rsp) for c in codes: self.assertEqual(204, c.status, msg=c.reason)