From da21e16aa0f248cb92ebf90a2de750e13887a008 Mon Sep 17 00:00:00 2001 From: Samuel Cassiba Date: Sun, 24 Jul 2016 13:57:15 -0700 Subject: [PATCH] Convert command line clients to openstackclient A prerequisite for Newton is to move to openstackclient for interfacing with the OpenStack services. Change-Id: I80a10bc1a3a50501306c16e278b960e43e9e9a59 Implements: blueprint openstackclient --- libraries/cli.rb | 8 ++++---- spec/cli_spec.rb | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libraries/cli.rb b/libraries/cli.rb index c61234aa..7b6c3af7 100644 --- a/libraries/cli.rb +++ b/libraries/cli.rb @@ -81,7 +81,7 @@ module ::Openstack # def get_uuid(client, type, key, value, env, args = {}, uuid_field = 'id') # rubocop: disable ParameterLists begin - output = openstack_command(client, "#{type}-list", env, args) + output = openstack_command(client, "#{type} list", env, args) prettytable_to_array(output).each do |obj| return obj[uuid_field] if obj.key?(uuid_field) && obj[key] == value end @@ -104,7 +104,7 @@ module ::Openstack # TODO: update openstack-identity register provider to use these functions. # def identity_uuid(*args) - get_uuid('keystone', *args) + get_uuid('openstack', *args) end # return id for a glance image. @@ -114,7 +114,7 @@ module ::Openstack # @param [Hash] optional command argument/values pairs # @return [String] id or nil def image_id(name, env, args = {}) - get_uuid('glance', 'image', 'Name', name, env, args, 'ID') + get_uuid('openstack', 'image', 'Name', name, env, args, 'ID') end # return uuid for a network resource. @@ -128,6 +128,6 @@ module ::Openstack # @return [String] uuid or nil # def network_uuid(*args) - get_uuid('neutron', *args) + get_uuid('openstack', *args) end end diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index e8db3401..cb53fa99 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -48,11 +48,11 @@ describe 'openstack-common::default' do 'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0' } allow(subject).to receive(:shell_out).with( - ['keystone', 'user-list'], + %w(openstack user list), env: env ).and_return double('shell_out', exitstatus: 0, stdout: 'good', stderr: '') - result = subject.openstack_command('keystone', 'user-list', env) + result = subject.openstack_command('openstack', 'user list', env) expect(result).to eq('good') end @@ -65,11 +65,11 @@ describe 'openstack-common::default' do 'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0' } allow(subject).to receive(:shell_out).with( - %w(keystone --key1 value1 --key2 value2 --key3 user-list), + %w(openstack --key1 value1 --key2 value2 --key3 user list), env: env ).and_return double('shell_out', exitstatus: 0, stdout: 'good', stderr: '') - result = subject.openstack_command('keystone', 'user-list', env, 'key1' => 'value1', 'key2' => 'value2', 'key3' => '') + result = subject.openstack_command('openstack', 'user list', env, 'key1' => 'value1', 'key2' => 'value2', 'key3' => '') expect(result).to eq('good') end @@ -82,7 +82,7 @@ describe 'openstack-common::default' do 'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0' } allow(subject).to receive(:shell_out).with( - ['keystone', 'user-list'], + %w(openstack user list), env: env ).and_return double('shell_out', exitstatus: 123, stdout: 'fail', stderr: '') @@ -100,7 +100,7 @@ describe 'openstack-common::default' do 'OS_TENANT_NAME' => 'tenant', 'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0' } - allow(subject).to receive(:openstack_command).with('keystone', 'user-list', env, {}) + allow(subject).to receive(:openstack_command).with('openstack', 'user list', env, {}) allow(subject).to receive(:prettytable_to_array) .and_return([{ 'name' => 'user1', 'id' => '1234567890ABCDEFGH' }]) @@ -120,7 +120,7 @@ describe 'openstack-common::default' do end it 'runs glance command to query valid id' do - allow(subject).to receive(:openstack_command).with('glance', 'image-list', :env, {}) + allow(subject).to receive(:openstack_command).with('openstack', 'image list', :env, {}) allow(subject).to receive(:prettytable_to_array) .and_return([{ 'ID' => '87f38e15-9737-46cc-a612-7c67ee29a24f', 'Name' => 'cirros' }]) @@ -129,7 +129,7 @@ describe 'openstack-common::default' do end it 'runs glance command to query invalid id' do - allow(subject).to receive(:openstack_command).with('glance', 'image-list', :env, {}) + allow(subject).to receive(:openstack_command).with('openstack', 'image list', :env, {}) .and_raise("No image with a name or ID of 'test' exists. (1)") expect { subject.image_id('test', :env) }.to raise_error(RuntimeError) @@ -145,11 +145,11 @@ describe 'openstack-common::default' do 'OS_TENANT_NAME' => 'tenant', 'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0' } - allow(subject).to receive(:openstack_command).with('neutron', 'net-list', env, {}) + allow(subject).to receive(:openstack_command).with('openstack', 'network list', env, {}) allow(subject).to receive(:prettytable_to_array) .and_return([{ 'name' => 'net1', 'id' => '1234567890ABCDEFGH' }]) - result = subject.network_uuid('net', 'name', 'net1', env) + result = subject.network_uuid('network', 'name', 'net1', env) expect(result).to eq('1234567890ABCDEFGH') end end