diff options
author | Zuul <zuul@review.opendev.org> | 2023-05-15 17:37:10 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-05-15 17:37:10 +0000 |
commit | 03b4409500d9c1ae0d68f897ccd717bbc7e8ba5e (patch) | |
tree | 3862a26c7b246c6fc2060a49c365058525d36aaa /neutron/tests | |
parent | beabb5193821a8427d8c5707f184c384bb848968 (diff) | |
parent | dde1d69c78fdada1d4441914e685f8a202f68896 (diff) | |
download | neutron-03b4409500d9c1ae0d68f897ccd717bbc7e8ba5e.tar.gz |
Merge "Add host metadata haproxy manager"
Diffstat (limited to 'neutron/tests')
-rw-r--r-- | neutron/tests/unit/agent/l2/extensions/metadata/__init__.py | 0 | ||||
-rw-r--r-- | neutron/tests/unit/agent/l2/extensions/metadata/test_host_metadata_proxy.py | 104 |
2 files changed, 104 insertions, 0 deletions
diff --git a/neutron/tests/unit/agent/l2/extensions/metadata/__init__.py b/neutron/tests/unit/agent/l2/extensions/metadata/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/neutron/tests/unit/agent/l2/extensions/metadata/__init__.py diff --git a/neutron/tests/unit/agent/l2/extensions/metadata/test_host_metadata_proxy.py b/neutron/tests/unit/agent/l2/extensions/metadata/test_host_metadata_proxy.py new file mode 100644 index 0000000000..c6a57d9846 --- /dev/null +++ b/neutron/tests/unit/agent/l2/extensions/metadata/test_host_metadata_proxy.py @@ -0,0 +1,104 @@ +# Copyright (c) 2022 China Unicom Cloud Data Co.,Ltd. +# 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 unittest import mock + +from oslo_config import cfg + +from neutron.agent.l2.extensions.metadata import host_metadata_proxy +from neutron.agent.linux import external_process +from neutron.tests import base + + +class TestHostMedataHAProxyDaemonMonitor(base.BaseTestCase): + + def setUp(self): + super(TestHostMedataHAProxyDaemonMonitor, self).setUp() + + self.ensure_dir = mock.patch( + 'oslo_utils.fileutils.ensure_tree').start() + + self.utils_exec_p = mock.patch( + 'neutron.agent.linux.utils.execute') + self.utils_exec = self.utils_exec_p.start() + + self.utils_replace_file_p = mock.patch( + 'neutron_lib.utils.file.replace_file') + self.utils_replace_file = self.utils_replace_file_p.start() + + def test_spawn_host_metadata_haproxy(self): + cfg.CONF.set_override('metadata_proxy_shared_secret', + 'secret', group='METADATA') + conffile = '/fake/host_metadata_proxy.haproxy.conf' + pidfile = '/fake/host_metadata_proxy.pid.haproxy' + process_monitor = external_process.ProcessMonitor( + config=cfg.CONF, + resource_type='MetadataPath') + + get_conf_file_name = 'neutron.agent.linux.utils.get_conf_file_name' + get_pid_file_name = ('neutron.agent.linux.external_process.' + 'ProcessManager.get_pid_file_name') + utils_execute = 'neutron.agent.common.utils.execute' + + mock.patch(get_conf_file_name).start().return_value = conffile + mock.patch(get_pid_file_name).start().return_value = pidfile + execute = mock.patch(utils_execute).start() + + host_meta = host_metadata_proxy.HostMedataHAProxyDaemonMonitor( + process_monitor) + instance_infos = [ + {"instance_id": "uuid1", + "provider_ip": "1.1.1.1", + "project_id": "project1"}] + host_meta.config(instance_infos) + host_meta.enable() + cmd = execute.call_args[0][0] + _join = lambda *args: ' '.join(args) + cmd = _join(*cmd) + self.assertIn('haproxy', cmd) + self.assertIn(_join('-f', conffile), cmd) + self.assertIn(_join('-p', pidfile), cmd) + + def test_generate_host_metadata_haproxy_config(self): + cfg.CONF.set_override('metadata_proxy_shared_secret', + 'secret', group='METADATA') + sig = ( + "3b5421875d7ba0fc910202f5ce448d9419597e7b66f702b53335116fee60e81e") + cfg.CONF.set_override('nova_metadata_host', + '2.2.2.2', + group='METADATA') + cfg.CONF.set_override('nova_metadata_port', + '8775', + group='METADATA') + process_monitor = external_process.ProcessMonitor( + config=cfg.CONF, + resource_type='MetadataPath') + host_meta = host_metadata_proxy.HostMedataHAProxyDaemonMonitor( + process_monitor) + instance_infos = [ + host_metadata_proxy.ProxyInstance('uuid1', '1.1.1.1', 'project1')] + host_meta._generate_proxy_conf(instance_infos) + acl = "acl instance_uuid1_1.1.1.1 src 1.1.1.1" + use_acl = "use_backend backend_uuid1_1.1.1.1 if instance_uuid1_1.1.1.1" + backend = "backend backend_uuid1_1.1.1.1" + http_hd_ins_id = "http-request set-header X-Instance-ID uuid1" + http_hd_pj = "http-request set-header X-Tenant-ID project1" + http_hd_sig = ( + "http-request set-header X-Instance-ID-Signature %s" % sig) + meta_real_srv = "server metasrv 2.2.2.2:8775" + expects = [acl, use_acl, backend, http_hd_ins_id, http_hd_pj, + http_hd_sig, meta_real_srv] + for exp in expects: + self.assertIn(exp, self.utils_replace_file.call_args[0][1]) |