def test_create_key_non_container_no_import(self): fake_module = "fake" fake_result = "fake" fake_cluster = "fake" fake_name = "client.fake" fake_secret = "super-secret" fake_caps = { 'mon': 'allow *', 'osd': 'allow rwx', } fake_dest = "/fake/ceph" fake_import_key = False fake_keyring_filename = fake_cluster + "." + fake_name + ".keyring" fake_file_destination = os.path.join(fake_dest, fake_keyring_filename) # create_key passes (one for ceph-authtool and one for itself) itw own array so the expected result is an array within an array # noqa E501 expected_command_list = [[ 'ceph-authtool', '--create-keyring', fake_file_destination, '--name', fake_name, '--add-key', fake_secret, '--cap', 'mon', 'allow *', '--cap', 'osd', 'allow rwx', ]] result = ceph_key.create_key(fake_module, fake_result, fake_cluster, 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): fake_module = "fake" fake_result = "fake" fake_cluster = "fake" fake_name = "client.fake" fake_secret = "super-secret" fake_caps = { 'mon': 'allow *', 'osd': 'allow rwx', } fake_dest = "/fake/ceph" fake_import_key = False fake_keyring_filename = fake_cluster + "." + fake_name + ".keyring" fake_file_destination = os.path.join(fake_dest, fake_keyring_filename) # create_key passes (one for ceph-authtool and one for itself) itw own array so the expected result is an array within an array # noqa E501 fake_container_image = "quay.ceph.io/ceph-ci/daemon:latest-luminous" expected_command_list = [[ 'docker', '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-authtool', 'quay.ceph.io/ceph-ci/daemon:latest-luminous', '--create-keyring', fake_file_destination, '--name', fake_name, '--add-key', fake_secret, '--cap', 'mon', 'allow *', '--cap', 'osd', 'allow rwx' ]] result = ceph_key.create_key(fake_module, fake_result, fake_cluster, fake_name, fake_secret, fake_caps, fake_import_key, fake_file_destination, fake_container_image) assert result == expected_command_list
def test_create_key_non_container(self): fake_module = "fake" fake_user = '******' fake_user_key = '/etc/ceph/fake.client.admin.keyring' fake_result = " fake" fake_cluster = "fake" fake_name = "client.fake" fake_secret = "super-secret" fake_caps = { 'mon': 'allow *', 'osd': 'allow rwx', } fake_import_key = True fake_dest = "/fake/ceph" fake_keyring_filename = fake_cluster + "." + fake_name + ".keyring" fake_file_destination = os.path.join(fake_dest, fake_keyring_filename) expected_command_list = [ [ 'ceph-authtool', '--create-keyring', fake_file_destination, '--name', fake_name, '--add-key', fake_secret, '--cap', 'mon', 'allow *', '--cap', 'osd', 'allow rwx' ], [ 'ceph', '-n', fake_user, '-k', fake_user_key, '--cluster', fake_cluster, 'auth', 'import', '-i', fake_file_destination ], ] result = ceph_key.create_key(fake_module, fake_result, fake_cluster, fake_user, fake_user_key, fake_name, fake_secret, fake_caps, fake_import_key, fake_file_destination) assert result == expected_command_list
def test_create_key_container(self): fake_module = "fake" fake_result = "fake" fake_cluster = "fake" fake_name = "client.fake" fake_secret = "super-secret" fake_caps = { 'mon': 'allow *', 'osd': 'allow rwx', } fake_dest = "/fake/ceph" fake_import_key = True fake_keyring_filename = fake_cluster + "." + fake_name + ".keyring" fake_file_destination = os.path.join(fake_dest, fake_keyring_filename) fake_container_image = "docker.io/ceph/daemon:latest-luminous" 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-authtool', 'docker.io/ceph/daemon:latest-luminous', '--create-keyring', fake_file_destination, '--name', fake_name, '--add-key', fake_secret, '--cap', 'mon', 'allow *', '--cap', 'osd', 'allow rwx'], ['docker', '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', '--cluster', fake_cluster, 'auth', 'import', '-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_file_destination, fake_container_image) # noqa E501 assert result == expected_command_list