summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-02-19 20:06:13 +0000
committerGerrit Code Review <review@openstack.org>2018-02-19 20:06:13 +0000
commit125dd1f30fdaf50182256c56808a5199856383c7 (patch)
treed25c9f40d75f3963d772c4a8bed593bfed5b6c3e
parent31a840c2fd9fb9154be31ac3b2b7a6f56e7e35a9 (diff)
parentc4d700dc20de831eaabfddaf5554319fd0d997ab (diff)
Merge "Use proper user and tenant in the owner section of libvirt.xml." into stable/ocatastable/ocata
-rw-r--r--nova/compute/api.py3
-rw-r--r--nova/tests/unit/virt/libvirt/test_driver.py46
-rw-r--r--nova/virt/libvirt/driver.py19
3 files changed, 53 insertions, 15 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 6f1371b..b3be366 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1503,6 +1503,9 @@ class API(base.Base):
1503 # In case we couldn't find any suitable base_image 1503 # In case we couldn't find any suitable base_image
1504 system_meta.setdefault('image_base_image_ref', instance.image_ref) 1504 system_meta.setdefault('image_base_image_ref', instance.image_ref)
1505 1505
1506 system_meta['owner_user_name'] = context.user_name
1507 system_meta['owner_project_name'] = context.project_name
1508
1506 instance.system_metadata.update(system_meta) 1509 instance.system_metadata.update(system_meta)
1507 1510
1508 if CONF.use_neutron: 1511 if CONF.use_neutron:
diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py
index 0988088..a445433 100644
--- a/nova/tests/unit/virt/libvirt/test_driver.py
+++ b/nova/tests/unit/virt/libvirt/test_driver.py
@@ -635,7 +635,7 @@ def _create_test_instance():
635 'instance_type_id': '5', # m1.small 635 'instance_type_id': '5', # m1.small
636 'extra_specs': {}, 636 'extra_specs': {},
637 'system_metadata': { 637 'system_metadata': {
638 'image_disk_format': 'raw', 638 'image_disk_format': 'raw'
639 }, 639 },
640 'flavor': flavor, 640 'flavor': flavor,
641 'new_flavor': None, 641 'new_flavor': None,
@@ -1847,6 +1847,8 @@ class LibvirtConnTestCase(test.NoDBTestCase):
1847 1847
1848 test_instance = copy.deepcopy(self.test_instance) 1848 test_instance = copy.deepcopy(self.test_instance)
1849 test_instance["display_name"] = "purple tomatoes" 1849 test_instance["display_name"] = "purple tomatoes"
1850 test_instance['system_metadata']['owner_project_name'] = 'sweetshop'
1851 test_instance['system_metadata']['owner_user_name'] = 'cupcake'
1850 1852
1851 ctxt = context.RequestContext(project_id=123, 1853 ctxt = context.RequestContext(project_id=123,
1852 project_name="aubergine", 1854 project_name="aubergine",
@@ -1921,13 +1923,13 @@ class LibvirtConnTestCase(test.NoDBTestCase):
1921 1923
1922 self.assertIsInstance(cfg.metadata[0].owner, 1924 self.assertIsInstance(cfg.metadata[0].owner,
1923 vconfig.LibvirtConfigGuestMetaNovaOwner) 1925 vconfig.LibvirtConfigGuestMetaNovaOwner)
1924 self.assertEqual(456, 1926 self.assertEqual("838a72b0-0d54-4827-8fd6-fb1227633ceb",
1925 cfg.metadata[0].owner.userid) 1927 cfg.metadata[0].owner.userid)
1926 self.assertEqual("pie", 1928 self.assertEqual("cupcake",
1927 cfg.metadata[0].owner.username) 1929 cfg.metadata[0].owner.username)
1928 self.assertEqual(123, 1930 self.assertEqual("fake",
1929 cfg.metadata[0].owner.projectid) 1931 cfg.metadata[0].owner.projectid)
1930 self.assertEqual("aubergine", 1932 self.assertEqual("sweetshop",
1931 cfg.metadata[0].owner.projectname) 1933 cfg.metadata[0].owner.projectname)
1932 1934
1933 self.assertIsInstance(cfg.metadata[0].flavor, 1935 self.assertIsInstance(cfg.metadata[0].flavor,
@@ -1945,6 +1947,40 @@ class LibvirtConnTestCase(test.NoDBTestCase):
1945 self.assertEqual(33550336, 1947 self.assertEqual(33550336,
1946 cfg.metadata[0].flavor.swap) 1948 cfg.metadata[0].flavor.swap)
1947 1949
1950 def test_get_guest_config_missing_ownership_info(self):
1951 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
1952
1953 test_instance = copy.deepcopy(self.test_instance)
1954
1955 ctxt = context.RequestContext(project_id=123,
1956 project_name="aubergine",
1957 user_id=456,
1958 user_name="pie")
1959
1960 flavor = objects.Flavor(name='m1.small',
1961 memory_mb=6,
1962 vcpus=28,
1963 root_gb=496,
1964 ephemeral_gb=8128,
1965 swap=33550336,
1966 extra_specs={})
1967 instance_ref = objects.Instance(**test_instance)
1968 instance_ref.flavor = flavor
1969 image_meta = objects.ImageMeta.from_dict(self.test_image_meta)
1970
1971 disk_info = blockinfo.get_disk_info(CONF.libvirt.virt_type,
1972 instance_ref,
1973 image_meta)
1974
1975 cfg = drvr._get_guest_config(instance_ref,
1976 _fake_network_info(self, 1),
1977 image_meta, disk_info,
1978 context=ctxt)
1979 self.assertEqual("N/A",
1980 cfg.metadata[0].owner.username)
1981 self.assertEqual("N/A",
1982 cfg.metadata[0].owner.projectname)
1983
1948 def test_get_guest_config_lxc(self): 1984 def test_get_guest_config_lxc(self):
1949 self.flags(virt_type='lxc', group='libvirt') 1985 self.flags(virt_type='lxc', group='libvirt')
1950 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) 1986 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index db2acdd..2c56ea0 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -3839,7 +3839,7 @@ class LibvirtDriver(driver.ComputeDriver):
3839 3839
3840 return dev 3840 return dev
3841 3841
3842 def _get_guest_config_meta(self, context, instance): 3842 def _get_guest_config_meta(self, instance):
3843 """Get metadata config for guest.""" 3843 """Get metadata config for guest."""
3844 3844
3845 meta = vconfig.LibvirtConfigGuestMetaNovaInstance() 3845 meta = vconfig.LibvirtConfigGuestMetaNovaInstance()
@@ -3851,13 +3851,13 @@ class LibvirtDriver(driver.ComputeDriver):
3851 meta.roottype = "image" 3851 meta.roottype = "image"
3852 meta.rootid = instance.image_ref 3852 meta.rootid = instance.image_ref
3853 3853
3854 if context is not None: 3854 system_meta = instance.system_metadata
3855 ometa = vconfig.LibvirtConfigGuestMetaNovaOwner() 3855 ometa = vconfig.LibvirtConfigGuestMetaNovaOwner()
3856 ometa.userid = context.user_id 3856 ometa.userid = instance.user_id
3857 ometa.username = context.user_name 3857 ometa.username = system_meta.get('owner_user_name', 'N/A')
3858 ometa.projectid = context.project_id 3858 ometa.projectid = instance.project_id
3859 ometa.projectname = context.project_name 3859 ometa.projectname = system_meta.get('owner_project_name', 'N/A')
3860 meta.owner = ometa 3860 meta.owner = ometa
3861 3861
3862 fmeta = vconfig.LibvirtConfigGuestMetaNovaFlavor() 3862 fmeta = vconfig.LibvirtConfigGuestMetaNovaFlavor()
3863 flavor = instance.flavor 3863 flavor = instance.flavor
@@ -4778,8 +4778,7 @@ class LibvirtDriver(driver.ComputeDriver):
4778 guest_numa_config.numatune, 4778 guest_numa_config.numatune,
4779 flavor) 4779 flavor)
4780 4780
4781 guest.metadata.append(self._get_guest_config_meta(context, 4781 guest.metadata.append(self._get_guest_config_meta(instance))
4782 instance))
4783 guest.idmaps = self._get_guest_idmaps() 4782 guest.idmaps = self._get_guest_idmaps()
4784 4783
4785 for event in self._supported_perf_events: 4784 for event in self._supported_perf_events: