From aa086f1a476aa505e3fd4218679101edeb82a6b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Han?= Date: Tue, 27 Nov 2018 09:59:07 +0100 Subject: [PATCH] ceph_key: fix after rebase MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix the tests Signed-off-by: Sébastien Han --- library/ceph_key.py | 2 +- library/test_ceph_key.py | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/library/ceph_key.py b/library/ceph_key.py index f25275e5c..9b42a06b7 100644 --- a/library/ceph_key.py +++ b/library/ceph_key.py @@ -590,7 +590,7 @@ def run_module(): module.exit_json(**result) rc, cmd, out, err = exec_commands(module, create_key( - module, result, cluster, name, secret, caps, import_key, dest, container_image)) # noqa E501 + module, result, cluster, name, secret, caps, import_key, file_path, container_image)) # noqa E501 file_args = module.load_file_common_arguments(module.params) file_args['path'] = file_path diff --git a/library/test_ceph_key.py b/library/test_ceph_key.py index 7a2a7c9ca..7a99bb321 100644 --- a/library/test_ceph_key.py +++ b/library/test_ceph_key.py @@ -1,8 +1,10 @@ import json import os from . import ceph_key +import mock +@mock.patch.dict(os.environ, {'CEPH_CONTAINER_BINARY': 'docker'}) class TestCephKeyModule(object): def test_generate_secret(self): @@ -120,7 +122,7 @@ class TestCephKeyModule(object): 'allow rwx', ] result = ceph_key.generate_ceph_authtool_cmd( - fake_cluster, fake_name, fake_secret, fake_caps, fake_dest) # noqa E501 + fake_cluster, fake_name, fake_secret, fake_caps, fake_file_destination) # noqa E501 assert result == expected_command_list def test_generate_ceph_authtool_cmd_container(self): @@ -157,7 +159,7 @@ class TestCephKeyModule(object): 'osd', 'allow rwx'] result = ceph_key.generate_ceph_authtool_cmd( - fake_cluster, fake_name, fake_secret, fake_caps, fake_dest, fake_container_image) # noqa E501 + fake_cluster, fake_name, fake_secret, fake_caps, fake_file_destination, fake_container_image) # noqa E501 assert result == expected_command_list def test_create_key_non_container(self): @@ -181,7 +183,7 @@ class TestCephKeyModule(object): 'import', '-i', fake_file_destination], ] result = ceph_key.create_key(fake_module, fake_result, fake_cluster, - fake_name, fake_secret, fake_caps, fake_import_key, fake_dest) # noqa E501 + fake_name, fake_secret, fake_caps, fake_import_key, fake_file_destination) # noqa E501 assert result == expected_command_list def test_create_key_container(self): @@ -230,7 +232,7 @@ class TestCephKeyModule(object): '-i', fake_file_destination] ] result = ceph_key.create_key(fake_module, fake_result, fake_cluster, fake_name, # noqa E501 - fake_secret, fake_caps, fake_import_key, fake_dest, fake_container_image) # noqa E501 + fake_secret, fake_caps, fake_import_key, fake_file_destination, fake_container_image) # noqa E501 assert result == expected_command_list def test_create_key_non_container_no_import(self): @@ -264,7 +266,7 @@ class TestCephKeyModule(object): 'allow rwx', ] ] result = ceph_key.create_key(fake_module, fake_result, fake_cluster, - fake_name, fake_secret, fake_caps, fake_import_key, fake_dest) # noqa E501 + fake_name, fake_secret, fake_caps, fake_import_key, fake_file_destination) # noqa E501 assert result == expected_command_list def test_create_key_container_no_import(self): @@ -305,7 +307,7 @@ class TestCephKeyModule(object): 'osd', 'allow rwx']] result = ceph_key.create_key(fake_module, fake_result, fake_cluster, fake_name, # noqa E501 - fake_secret, fake_caps, fake_import_key, fake_dest, fake_container_image) # noqa E501 + fake_secret, fake_caps, fake_import_key, fake_file_destination, fake_container_image) # noqa E501 assert result == expected_command_list def test_update_key_non_container(self): @@ -436,16 +438,27 @@ class TestCephKeyModule(object): def test_get_key_container(self): fake_cluster = "fake" fake_name = "client.fake" - fake_containerized = "docker exec -ti ceph-mon" + fake_container_image = "docker.io/ceph/daemon:latest-luminous" fake_dest = "/fake/ceph" fake_file_destination = os.path.join( fake_dest + "/" + fake_cluster + "." + fake_name + ".keyring") - expected_command_list = [ - ['docker', 'exec', '-ti', 'ceph-mon', 'ceph', '-n', "client.admin", '-k', "/etc/ceph/fake.client.admin.keyring", '--cluster', # noqa E501 - fake_cluster, 'auth', 'get', fake_name, '-o', fake_file_destination], # noqa E501 + expected_command_list = [['docker', # noqa E128 + 'run', + '--rm', + '--net=host', + '-v', '/etc/ceph:/etc/ceph:z', + '-v', '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + 'docker.io/ceph/daemon:latest-luminous', + '-n', "client.admin", + '-k', "/etc/ceph/fake.client.admin.keyring", # noqa E501 + '--cluster', fake_cluster, + 'auth', 'get', + fake_name, '-o', fake_file_destination], ] result = ceph_key.get_key( - fake_cluster, fake_name, fake_file_destination, fake_containerized) # noqa E501 + fake_cluster, fake_name, fake_file_destination, fake_container_image) # noqa E501 assert result == expected_command_list def test_get_key_non_container(self): -- 2.39.5