From 0357b01c12eb6b84b5038bbf465fd3b9d4921a29 Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Thu, 9 May 2013 15:44:38 +0100 Subject: xenapi: make the xenapi agent optional per image This adds the ability to decide, per image, if xenapi should use the agent for servers created from that image. This opens up the path to using config drive or the metadata service with cloud-init to perform tasks like file injection It uses the image properties that are copied into system metadata to detect if "xenapi_agent_present"="true" on the image the server was created from. If the tag is not present, it defaults to the value of the new conf setting "xenapi_agent_present_default". Becuase the above setting defaults to False, it means that the xenapi driver no longer waits for the agent by default. DocImpact fixes bug 1178223 part of blueprint xenapi-guest-agent-cloud-init-interop Change-Id: Ie51a9f54e5b2e85fe4ebebb0aff975db296ba996 --- nova/tests/virt/xenapi/imageupload/test_glance.py | 4 +- nova/tests/virt/xenapi/test_agent.py | 51 +++++++++++++++++++++++ nova/tests/virt/xenapi/test_xenapi.py | 2 + 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 nova/tests/virt/xenapi/test_agent.py (limited to 'nova/tests') diff --git a/nova/tests/virt/xenapi/imageupload/test_glance.py b/nova/tests/virt/xenapi/imageupload/test_glance.py index 34e95ab80..7b6fbd43d 100644 --- a/nova/tests/virt/xenapi/imageupload/test_glance.py +++ b/nova/tests/virt/xenapi/imageupload/test_glance.py @@ -48,10 +48,12 @@ class TestGlanceStore(test.TestCase): properties = { 'auto_disk_config': True, 'os_type': 'default', + 'xenapi_use_agent': 'true', } image_id = 'fake_image_uuid' vdi_uuids = ['fake_vdi_uuid'] - instance = {'uuid': 'blah'} + instance = {'uuid': 'blah', + 'system_metadata': {'image_xenapi_use_agent': 'true'}} instance.update(properties) params = {'vdi_uuids': vdi_uuids, diff --git a/nova/tests/virt/xenapi/test_agent.py b/nova/tests/virt/xenapi/test_agent.py new file mode 100644 index 000000000..9a4d7c345 --- /dev/null +++ b/nova/tests/virt/xenapi/test_agent.py @@ -0,0 +1,51 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 OpenStack Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +from nova import test +from nova.virt.xenapi import agent + + +class AgentEnabledCase(test.TestCase): + def test_agent_is_present(self): + self.flags(xenapi_use_agent_default=False) + instance = {"system_metadata": + {"image_xenapi_use_agent": "true"}} + self.assertTrue(agent.should_use_agent(instance)) + + def test_agent_is_disabled(self): + self.flags(xenapi_use_agent_default=True) + instance = {"system_metadata": + {"image_xenapi_use_agent": "false"}} + self.assertFalse(agent.should_use_agent(instance)) + + def test_agent_uses_deafault_when_prop_invalid(self): + self.flags(xenapi_use_agent_default=True) + instance = {"system_metadata": + {"image_xenapi_use_agent": "bob"}, + "uuid": "uuid"} + self.assertTrue(agent.should_use_agent(instance)) + + def test_agent_default_not_present(self): + self.flags(xenapi_use_agent_default=False) + instance = {"system_metadata": {}} + self.assertFalse(agent.should_use_agent(instance)) + + def test_agent_default_present(self): + self.flags(xenapi_use_agent_default=True) + instance = {"system_metadata": {}} + self.assertTrue(agent.should_use_agent(instance)) diff --git a/nova/tests/virt/xenapi/test_xenapi.py b/nova/tests/virt/xenapi/test_xenapi.py index af2d97f67..538752cf2 100644 --- a/nova/tests/virt/xenapi/test_xenapi.py +++ b/nova/tests/virt/xenapi/test_xenapi.py @@ -972,6 +972,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): def test_spawn_ssh_key_injection(self): # Test spawning with key_data on an instance. Should use # agent file injection. + self.flags(xenapi_use_agent_default=True) actual_injected_files = [] def fake_inject_file(self, method, args): @@ -999,6 +1000,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): def test_spawn_injected_files(self): # Test spawning with injected_files. + self.flags(xenapi_use_agent_default=True) actual_injected_files = [] def fake_inject_file(self, method, args): -- cgit