def test_index(self, m_res, m_os, m_pools): tenant = fakes.tenants["foo"] req = self._build_req(tenant["id"]) f = fakes.flavors[1] res_tpl = templates.OpenStackResourceTemplate(f["id"], f["name"], f["vcpus"], f["ram"], f["disk"]) m_res.return_value = [res_tpl] i = fakes.images["foo"] os_tpl = templates.OpenStackOSTemplate(i["id"], i["name"]) m_os.return_value = [os_tpl] ip_pool = os_network.OSFloatingIPPool("foo") m_pools.return_value = [ip_pool] expected = [ res_tpl, os_tpl, ip_pool, # OCCI Core Kinds: entity.Entity.kind, resource.Resource.kind, link.Link.kind, # OCCI infra Compute: compute.ComputeResource.kind, compute.start, compute.stop, compute.restart, compute.suspend, # OCCI infra Storage storage.StorageResource.kind, storage_link.StorageLink.kind, storage.online, storage.offline, storage.backup, storage.snapshot, storage.resize, # OCCI infra network network.NetworkResource.kind, network.up, network.down, network.ip_network, network_link.NetworkInterface.kind, network_link.ip_network_interface, # OCCI infra compute mixins infra_templates.os_tpl, infra_templates.resource_tpl, # OpenStack Contextualization contextualization.user_data, contextualization.public_key, ] ret = self.controller.index(req) self.assertItemsEqual(expected, ret)
def _os_tpls(self, req): images = self.os_helper.get_images(req) occi_os_templates = [] if images: for i in images: tpl = templates.OpenStackOSTemplate(i["id"], i["name"]) occi_os_templates.append(tpl) return occi_os_templates
def test_os_template(self): id = uuid.uuid4().hex title = "Frobble Image" tpl = templates.OpenStackOSTemplate(id, title) self.assertEqual(id, tpl.term) self.assertEqual(title, tpl.title) self.assertTrue(tpl.scheme.startswith(helpers._PREFIX)) self.assertIn(occi_templates.os_tpl, tpl.related)
def show(self, req, id): # get info from server s = self.os_helper.get_server(req, id) # get info from flavor flavor = self.os_helper.get_flavor(req, s["flavor"]["id"]) res_tpl = templates.OpenStackResourceTemplate(flavor["id"], flavor["name"], flavor["vcpus"], flavor["ram"], flavor["disk"]) # get info from image img_id = s["image"]["id"] try: image = self.os_helper.get_image(req, img_id) except webob.exc.HTTPNotFound: image = { "id": img_id, "name": "None (Image with ID '%s' not found)" % img_id, } os_tpl = templates.OpenStackOSTemplate(image["id"], image["name"]) # build the compute object comp = compute.ComputeResource(title=s["name"], id=s["id"], cores=flavor["vcpus"], hostname=s["name"], memory=flavor["ram"], state=helpers.vm_state(s["status"]), mixins=[os_tpl, res_tpl]) # storage links vols = self.os_helper.get_server_volumes_link(req, s["id"]) for v in vols: st = storage.StorageResource(title="storage", id=v["volumeId"]) comp.add_link( storage_link.StorageLink(comp, st, deviceid=v["device"])) # network links addresses = s.get("addresses", {}) if addresses: for addr_set in addresses.values(): for addr in addr_set: # TODO(jorgesece): add pool information if addr["OS-EXT-IPS:type"] == "floating": net_id = helpers.PUBLIC_NETWORK else: try: net_id = self.os_helper.get_network_id( req, addr['OS-EXT-IPS-MAC:mac_addr'], id) except webob.exc.HTTPNotFound: net_id = "FIXED" comp.add_link(_create_network_link(addr, comp, net_id)) return [comp]
def test_os_template(self): id = uuid.uuid4().hex title = "Frobble Image" location = "%s/%s" % (occi_templates.os_tpl._location, id) tpl = templates.OpenStackOSTemplate(id, title) self.assertEqual(id, tpl.term) self.assertEqual(title, tpl.title) self.assertTrue(tpl.scheme.startswith(helpers._PREFIX)) self.assertIn(occi_templates.os_tpl, tpl.depends) self.assertEqual(location, tpl.location)
def test_get_os_tpls(self, m_get_images): m_get_images.return_value = fakes.images.values() ret = self.controller._os_tpls(None) expected = [] for i in fakes.images.values(): expected.append(templates.OpenStackOSTemplate(i["id"], i["name"]), ) # FIXME(aloga): this won't work until we create the correct equality # functions # self.assertItemsEqual(expected, ret) for i in range(len(expected)): self.assertEqual(expected[i].title, ret[i].title)
def show(self, req, id): # get info from server s = self.os_helper.get_server(req, id) # get info from flavor flavor = self.os_helper.get_flavor(req, s["flavor"]["id"]) res_tpl = templates.OpenStackResourceTemplate(flavor["id"], flavor["name"], flavor["vcpus"], flavor["ram"], flavor["disk"]) # get info from image image = self.os_helper.get_image(req, s["image"]["id"]) os_tpl = templates.OpenStackOSTemplate(image["id"], image["name"]) # build the compute object comp = compute.ComputeResource(title=s["name"], id=s["id"], cores=flavor["vcpus"], hostname=s["name"], memory=flavor["ram"], state=helpers.vm_state(s["status"]), mixins=[os_tpl, res_tpl]) # storage links vols = self.os_helper.get_server_volumes_link(req, s["id"]) for v in vols: st = storage.StorageResource(title="storage", id=v["volumeId"]) comp.add_link( storage_link.StorageLink(comp, st, deviceid=v["device"])) # network links addresses = s.get("addresses", {}) if addresses: for addr_set in addresses.values(): for addr in addr_set: comp.add_link(_create_network_link(addr, comp)) return [comp]
def test_index_neutron(self, m_res, m_os, m_pools): neutron_controller = query.Controller(mock.MagicMock(), None, "http://foo") tenant = fakes.tenants["foo"] req = self._build_req(tenant["id"]) f = fakes.flavors[1] res_tpl = templates.OpenStackResourceTemplate(f["id"], f["name"], f["vcpus"], f["ram"], f["disk"]) m_res.return_value = [res_tpl] i = fakes.images["foo"] os_tpl = templates.OpenStackOSTemplate(i["id"], i["name"]) m_os.return_value = [os_tpl] ip_pool = os_network.OSFloatingIPPool("foo") m_pools.return_value = [ip_pool] expected_kinds = [ entity.Entity.kind, resource.Resource.kind, link.Link.kind, compute.ComputeResource.kind, storage.StorageResource.kind, storage_link.StorageLink.kind, network.NetworkResource.kind, network_link.NetworkInterface.kind, ip_reservation.IPReservation.kind, ] expected_mixins = [ res_tpl, os_tpl, ip_pool, os_network.neutron_network, network.ip_network, network_link.ip_network_interface, infra_templates.os_tpl, infra_templates.resource_tpl, os_contextualization.user_data, os_contextualization.public_key, contextualization.user_data, contextualization.ssh_key, ] expected_actions = [ compute.start, compute.stop, compute.restart, compute.suspend, storage.online, storage.offline, storage.backup, storage.snapshot, storage.resize, network.up, network.down, ] ret = neutron_controller.index(req) self.assertItemsEqual(expected_kinds, ret.kinds) self.assertItemsEqual(expected_mixins, ret.mixins) self.assertItemsEqual(expected_actions, ret.actions) self.assertEqual([], ret.resources) self.assertEqual([], ret.links)