def test_show_iface(self, m_show): tenant = fakes.tenants["foo"] m_show.return_value = fakes.fake_network_link_occi( fakes.network_links[tenant['id']] ) for ip in fakes.network_links[tenant["id"]]: if ip["instance_id"] is not None: link_id = '_'.join([ip["instance_id"], ip["network_id"], ip["ip"]] ) req = self._build_req("/networklink/%s" % link_id, tenant["id"], method="GET") resp = req.get_response(self.app) self.assertContentType(resp) # net_id = uuid.uuid4().hex source = utils.join_url(self.application_url + "/", "compute/%s" % ip["instance_id"]) target = utils.join_url(self.application_url + "/", "network/%s" % ip['network_id']) self.assertResultIncludesLinkAttr(link_id, source, target, resp) self.assertEqual(200, resp.status_code)
def test_show_iface(self, m_show): tenant = fakes.tenants["foo"] m_show.return_value = fakes.fake_network_link_occi( fakes.network_links[tenant['id']] ) for ip in fakes.network_links[tenant["id"]]: if ip["instance_id"] is not None: link_id = '_'.join([ip["instance_id"], ip["network_id"], ip["ip"]] ) req = self._build_req("/networklink/%s" % link_id, tenant["id"], method="GET") resp = req.get_response(self.app) self.assertContentType(resp) # net_id = uuid.uuid4().hex source = utils.join_url(self.application_url + "/", "compute/%s" % ip["instance_id"]) target = utils.join_url(self.application_url + "/", "network/%s" % ip['network_id']) self.assertResultIncludesLinkAttr(link_id, source, target, resp) self.assertEqual(200, resp.status_code)
def test_list_ifaces(self, mock_index): tenant = fakes.tenants["foo"] mock_index.return_value = collection.Collection( fakes.fake_network_link_occi( fakes.network_links[tenant['id']] ) ) for url in ("/networklink/", "/networklink"): req = self._build_req(url, tenant["id"], method="GET") resp = req.get_response(self.app) self.assertEqual(200, resp.status_code) expected = [] for ip in fakes.network_links[tenant["id"]]: if ip["instance_id"]: # fixme(jorgesece): test in case of instance None link_id = '_'.join([ip["instance_id"], ip["network_id"], ip["ip"]]) expected.append( ("X-OCCI-Location", utils.join_url(self.application_url + "/", "networklink/%s" % link_id)) ) self.assertExpectedResult(expected, resp)
def test_list_ifaces(self, mock_index): tenant = fakes.tenants["foo"] mock_index.return_value = collection.Collection( fakes.fake_network_link_occi( fakes.network_links[tenant['id']] ) ) for url in ("/networklink/", "/networklink"): req = self._build_req(url, tenant["id"], method="GET") resp = req.get_response(self.app) self.assertEqual(200, resp.status_code) expected = [] for ip in fakes.network_links[tenant["id"]]: if ip["instance_id"]: # fixme(jorgesece): test in case of instance None link_id = '_'.join([ip["instance_id"], ip["network_id"], ip["ip"]]) expected.append( ("X-OCCI-Location", utils.join_url(self.application_url + "/", "networklink/%s" % link_id)) ) self.assertExpectedResult(expected, resp)
def test_list_ifaces_empty(self, mock_index): tenant = fakes.tenants["bar"] mock_index.return_value = fakes.fake_network_link_occi( fakes.network_links[tenant['id']] ) for url in ("/networklink/", "/networklink"): req = self._build_req(url, tenant["id"], method="GET") req.environ["HTTP_X_PROJECT_ID"] = tenant["id"] resp = req.get_response(self.app) expected_result = "" self.assertContentType(resp) self.assertExpectedResult(expected_result, resp) self.assertEqual(204, resp.status_code)
def test_list_ifaces_empty(self, mock_index): tenant = fakes.tenants["bar"] mock_index.return_value = fakes.fake_network_link_occi( fakes.network_links[tenant['id']] ) for url in ("/networklink/", "/networklink"): req = self._build_req(url, tenant["id"], method="GET") req.environ["HTTP_X_PROJECT_ID"] = tenant["id"] resp = req.get_response(self.app) expected_result = "" self.assertContentType(resp) self.assertExpectedResult(expected_result, resp) self.assertEqual(204, resp.status_code)
def test_create_link_with_pool(self, m_create): tenant = fakes.tenants["foo"] m_create.return_value = collection.Collection( [fakes.fake_network_link_occi( fakes.network_links[tenant['id']] )[0]]) link_info = fakes.network_links[tenant['id']][0] server_url = utils.join_url(self.application_url + "/", "compute/%s" % link_info['instance_id']) net_url = utils.join_url(self.application_url + "/", "network/%s" % link_info['network_id']) pool_name = 'pool' headers = { 'Category': ( 'networkinterface;' 'scheme="http://schemas.ogf.org/occi/infrastructure#";' 'class="kind",' '%s;' 'scheme="http://schemas.openstack.org/network/' 'floatingippool#"; class="mixin"') % pool_name, 'X-OCCI-Attribute': ( 'occi.core.source="%s", ' 'occi.core.target="%s"' ) % (server_url, net_url) } req = self._build_req("/networklink", tenant["id"], method="POST", headers=headers) resp = req.get_response(self.app) link_id = '_'.join([link_info['instance_id'], link_info['network_id'], link_info['ip']]) expected = [("X-OCCI-Location", utils.join_url(self.application_url + "/", "networklink/%s" % link_id))] self.assertEqual(200, resp.status_code) self.assertExpectedResult(expected, resp) self.assertDefaults(resp)
def test_create_link_no_pool(self, m_create): tenant = fakes.tenants["foo"] m_create.return_value = fakes.fake_network_link_occi( fakes.network_links[tenant['id']] )[0] net_id = fakes.network_links[tenant['id']][0]['network_id'] occi_net_id = utils.join_url(self.application_url + "/", "network/%s" % net_id) headers = { 'Category': ( 'networkinterface;' 'scheme="http://schemas.ogf.org/occi/infrastructure#";' 'class="kind"'), 'X-OCCI-Attribute': ( 'occi.core.source="foo", ' 'occi.core.target="%s"' ) % occi_net_id } req = self._build_req("/networklink", None, method="POST", headers=headers) resp = req.get_response(self.app) self.assertEqual(200, resp.status_code)
def test_create_link_with_pool(self, m_create): tenant = fakes.tenants["foo"] m_create.return_value = collection.Collection( [fakes.fake_network_link_occi( fakes.network_links[tenant['id']] )[0]]) link_info = fakes.network_links[tenant['id']][0] server_url = utils.join_url(self.application_url + "/", "compute/%s" % link_info['instance_id']) net_url = utils.join_url(self.application_url + "/", "network/%s" % link_info['network_id']) pool_name = 'pool' headers = { 'Category': ( 'networkinterface;' 'scheme="http://schemas.ogf.org/occi/infrastructure#";' 'class="kind",' '%s;' 'scheme="http://schemas.openstack.org/network/' 'floatingippool#"; class="mixin"') % pool_name, 'X-OCCI-Attribute': ( 'occi.core.source="%s", ' 'occi.core.target="%s"' ) % (server_url, net_url) } req = self._build_req("/networklink", tenant["id"], method="POST", headers=headers) resp = req.get_response(self.app) link_id = '_'.join([link_info['instance_id'], link_info['network_id'], link_info['ip']]) expected = [("X-OCCI-Location", utils.join_url(self.application_url + "/", "networklink/%s" % link_id))] self.assertEqual(200, resp.status_code) self.assertExpectedResult(expected, resp) self.assertDefaults(resp)
def test_create_link_no_pool(self, m_create): tenant = fakes.tenants["foo"] m_create.return_value = fakes.fake_network_link_occi( fakes.network_links[tenant['id']] )[0] net_id = fakes.network_links[tenant['id']][0]['network_id'] occi_net_id = utils.join_url(self.application_url + "/", "network/%s" % net_id) headers = { 'Category': ( 'networkinterface;' 'scheme="http://schemas.ogf.org/occi/infrastructure#";' 'class="kind"'), 'X-OCCI-Attribute': ( 'occi.core.source="foo", ' 'occi.core.target="%s"' ) % occi_net_id } req = self._build_req("/networklink", None, method="POST", headers=headers) resp = req.get_response(self.app) self.assertEqual(200, resp.status_code)