From 64eefb9b2277f13ca758bb8c314195b6045fd6a2 Mon Sep 17 00:00:00 2001 From: Ashley Rodriguez Date: Mon, 16 May 2022 20:09:21 +0000 Subject: [PATCH] [OSC] Add OSC Functional Tests Network Adds osc functional tests for share network create, delete, show, list, set and unset Partially-implements: bp openstack-client-support Change-Id: I8f1a32db3d7284e1cd64a1c91c9ddcdbc43be242 --- manilaclient/tests/functional/osc/base.py | 24 ++++- .../functional/osc/test_share_networks.py | 89 +++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 manilaclient/tests/functional/osc/test_share_networks.py diff --git a/manilaclient/tests/functional/osc/base.py b/manilaclient/tests/functional/osc/base.py index 288858d6e..c7d397823 100644 --- a/manilaclient/tests/functional/osc/base.py +++ b/manilaclient/tests/functional/osc/base.py @@ -294,9 +294,31 @@ class OSCClientTestBase(base.ClientTestBase): snapshot_object = self.dict_result('share', cmd) self._wait_for_object_status( 'share snapshot', snapshot_object['id'], 'available') - if add_cleanup: self.addCleanup( self.openstack, f'share snapshot delete {snapshot_object["id"]} --wait') return snapshot_object + + def create_share_network(self, neutron_net_id=None, + neutron_subnet_id=None, name=None, + description=None, availability_zone=None, + add_cleanup=True): + name = name or data_utils.rand_name('autotest_share_network_name') + cmd = (f'network create --name {name} --description {description}') + if neutron_net_id: + cmd = cmd + f' --neutron-net-id {neutron_net_id}' + if neutron_subnet_id: + cmd = cmd + f' --neutron-subnet-id {neutron_subnet_id}' + if availability_zone: + cmd = cmd + f' --availability-zone {availability_zone}' + + share_network_obj = self.dict_result('share', cmd) + self._wait_for_object_status( + 'share network', share_network_obj['id'], 'active') + if add_cleanup: + self.addCleanup( + self.openstack, + f'share network delete {share_network_obj["id"]}' + ) + return share_network_obj diff --git a/manilaclient/tests/functional/osc/test_share_networks.py b/manilaclient/tests/functional/osc/test_share_networks.py new file mode 100644 index 000000000..7739078b8 --- /dev/null +++ b/manilaclient/tests/functional/osc/test_share_networks.py @@ -0,0 +1,89 @@ +# 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 manilaclient.tests.functional.osc import base + + +class ShareNetworksCLITest(base.OSCClientTestBase): + + def test_openstack_share_network_create(self): + share_network_name = 'test_create_share_network' + share_network = self.create_share_network(name=share_network_name) + + self.assertEqual(share_network['name'], share_network_name) + + share_network_list = self.listing_result('share network', 'list') + self.assertIn(share_network['id'], + [item['ID'] for item in share_network_list]) + + def test_openstack_share_network_list(self): + share_network = self.create_share_network() + share_network_list = self.listing_result('share network', 'list') + self.assertTableStruct(share_network_list, [ + 'ID', + 'Name', + ]) + self.assertIn(share_network['id'], + [item['ID'] for item in share_network_list]) + + def test_openstack_share_network_show(self): + share_network = self.create_share_network() + + result = self.dict_result('share network', + 'show %s' % share_network['id']) + self.assertEqual(share_network['id'], result['id']) + + listing_result = self.listing_result('share network', + 'show %s' % share_network['id']) + self.assertTableStruct(listing_result, [ + 'Field', + 'Value' + ]) + + def test_openstack_share_network_delete(self): + share_network = self.create_share_network(add_cleanup=False) + share_network_list = self.listing_result('share network', 'list') + + self.assertIn(share_network['id'], + [item['ID'] for item in share_network_list]) + + self.openstack('share network delete %s' % share_network['id']) + self.check_object_deleted('share network', share_network['id']) + share_network_list_after_delete = self.listing_result('share network', + 'list') + + self.assertNotIn( + share_network['id'], + [item['ID'] for item in share_network_list_after_delete]) + + def test_openstack_share_network_set(self): + share_network = self.create_share_network() + self.openstack('share network set %s --name %s' + % (share_network['id'], 'new_name')) + result = self.dict_result('share network', 'show %s' % + share_network['id']) + self.assertEqual(share_network['id'], result['id']) + self.assertEqual('new_name', result['name']) + + def test_openstack_share_network_unset(self): + share_network = self.create_share_network(name='test_name') + result1 = self.dict_result('share network', 'show %s' % + share_network['id']) + self.assertEqual(share_network['id'], result1['id']) + self.assertEqual(share_network['name'], result1['name']) + + self.openstack('share network unset %s --name' + % (share_network['id'])) + result2 = self.dict_result('share network', 'show %s' % + share_network['id']) + self.assertEqual(share_network['id'], result2['id']) + self.assertEqual('None', result2['name'])