summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/functional/compute/v2/test_agent.py4
-rw-r--r--openstackclient/tests/functional/compute/v2/test_aggregate.py62
-rw-r--r--openstackclient/tests/functional/compute/v2/test_keypair.py4
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server.py43
-rw-r--r--openstackclient/tests/functional/identity/v2/common.py3
-rw-r--r--openstackclient/tests/functional/identity/v3/common.py4
-rw-r--r--openstackclient/tests/functional/identity/v3/test_role.py25
-rw-r--r--openstackclient/tests/functional/object/v1/test_object.py2
-rw-r--r--openstackclient/tests/functional/volume/v3/test_qos.py204
-rw-r--r--openstackclient/tests/functional/volume/v3/test_transfer_request.py106
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume.py268
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume_snapshot.py240
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume_type.py224
-rw-r--r--openstackclient/tests/unit/api/test_object_store_v1.py4
-rw-r--r--openstackclient/tests/unit/common/test_availability_zone.py8
-rw-r--r--openstackclient/tests/unit/common/test_command.py2
-rw-r--r--openstackclient/tests/unit/common/test_configuration.py2
-rw-r--r--openstackclient/tests/unit/common/test_extension.py23
-rw-r--r--openstackclient/tests/unit/common/test_logs.py3
-rw-r--r--openstackclient/tests/unit/common/test_module.py2
-rw-r--r--openstackclient/tests/unit/common/test_project_purge.py2
-rw-r--r--openstackclient/tests/unit/common/test_quota.py2
-rw-r--r--openstackclient/tests/unit/compute/v2/fakes.py2
-rw-r--r--openstackclient/tests/unit/compute/v2/test_agent.py4
-rw-r--r--openstackclient/tests/unit/compute/v2/test_aggregate.py4
-rw-r--r--openstackclient/tests/unit/compute/v2/test_console.py2
-rw-r--r--openstackclient/tests/unit/compute/v2/test_flavor.py4
-rw-r--r--openstackclient/tests/unit/compute/v2/test_host.py2
-rw-r--r--openstackclient/tests/unit/compute/v2/test_keypair.py4
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server.py256
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server_backup.py2
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server_group.py2
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server_image.py2
-rw-r--r--openstackclient/tests/unit/compute/v2/test_service.py5
-rw-r--r--openstackclient/tests/unit/compute/v2/test_usage.py2
-rw-r--r--openstackclient/tests/unit/fakes.py6
-rw-r--r--openstackclient/tests/unit/identity/v2_0/fakes.py2
-rw-r--r--openstackclient/tests/unit/identity/v2_0/test_catalog.py2
-rw-r--r--openstackclient/tests/unit/identity/v2_0/test_project.py2
-rw-r--r--openstackclient/tests/unit/identity/v2_0/test_role.py2
-rw-r--r--openstackclient/tests/unit/identity/v2_0/test_role_assignment.py2
-rw-r--r--openstackclient/tests/unit/identity/v2_0/test_token.py2
-rw-r--r--openstackclient/tests/unit/identity/v2_0/test_user.py2
-rw-r--r--openstackclient/tests/unit/identity/v3/fakes.py36
-rw-r--r--openstackclient/tests/unit/identity/v3/test_access_rule.py174
-rw-r--r--openstackclient/tests/unit/identity/v3/test_application_credential.py127
-rw-r--r--openstackclient/tests/unit/identity/v3/test_catalog.py2
-rw-r--r--openstackclient/tests/unit/identity/v3/test_credential.py4
-rw-r--r--openstackclient/tests/unit/identity/v3/test_endpoint_group.py2
-rw-r--r--openstackclient/tests/unit/identity/v3/test_group.py4
-rw-r--r--openstackclient/tests/unit/identity/v3/test_identity_provider.py3
-rw-r--r--openstackclient/tests/unit/identity/v3/test_mappings.py2
-rw-r--r--openstackclient/tests/unit/identity/v3/test_project.py26
-rw-r--r--openstackclient/tests/unit/identity/v3/test_role.py81
-rw-r--r--openstackclient/tests/unit/identity/v3/test_role_assignment.py3
-rw-r--r--openstackclient/tests/unit/identity/v3/test_token.py2
-rw-r--r--openstackclient/tests/unit/identity/v3/test_trust.py2
-rw-r--r--openstackclient/tests/unit/identity/v3/test_user.py2
-rw-r--r--openstackclient/tests/unit/image/v1/fakes.py3
-rw-r--r--openstackclient/tests/unit/image/v1/test_image.py3
-rw-r--r--openstackclient/tests/unit/image/v2/fakes.py2
-rw-r--r--openstackclient/tests/unit/image/v2/test_image.py2
-rw-r--r--openstackclient/tests/unit/integ/cli/test_shell.py2
-rw-r--r--openstackclient/tests/unit/network/test_common.py2
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py81
-rw-r--r--openstackclient/tests/unit/network/v2/test_address_scope.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_floating_ip_compute.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_floating_ip_network.py30
-rw-r--r--openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_floating_ip_port_forwarding.py502
-rw-r--r--openstackclient/tests/unit/network/v2/test_ip_availability.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_network.py38
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_agent.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_compute.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_flavor.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_flavor_profile.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_meter.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_meter_rule.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_qos_policy.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_qos_rule.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_rbac.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_segment.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_segment_range.py18
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_service_provider.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_port.py6
-rw-r--r--openstackclient/tests/unit/network/v2/test_router.py22
-rw-r--r--openstackclient/tests/unit/network/v2/test_security_group_compute.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_security_group_network.py21
-rw-r--r--openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_security_group_rule_network.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_subnet.py4
-rw-r--r--openstackclient/tests/unit/network/v2/test_subnet_pool.py5
-rw-r--r--openstackclient/tests/unit/object/v1/fakes.py3
-rw-r--r--openstackclient/tests/unit/object/v1/test_container.py3
-rw-r--r--openstackclient/tests/unit/object/v1/test_container_all.py72
-rw-r--r--openstackclient/tests/unit/object/v1/test_object.py3
-rw-r--r--openstackclient/tests/unit/object/v1/test_object_all.py2
-rw-r--r--openstackclient/tests/unit/test_shell.py2
-rw-r--r--openstackclient/tests/unit/utils.py15
-rw-r--r--openstackclient/tests/unit/volume/test_find_resource.py2
-rw-r--r--openstackclient/tests/unit/volume/v1/fakes.py3
-rw-r--r--openstackclient/tests/unit/volume/v1/test_qos_specs.py5
-rw-r--r--openstackclient/tests/unit/volume/v1/test_transfer_request.py4
-rw-r--r--openstackclient/tests/unit/volume/v1/test_type.py4
-rw-r--r--openstackclient/tests/unit/volume/v1/test_volume.py5
-rw-r--r--openstackclient/tests/unit/volume/v1/test_volume_backup.py4
-rw-r--r--openstackclient/tests/unit/volume/v2/fakes.py3
-rw-r--r--openstackclient/tests/unit/volume/v2/test_consistency_group.py4
-rw-r--r--openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py2
-rw-r--r--openstackclient/tests/unit/volume/v2/test_qos_specs.py5
-rw-r--r--openstackclient/tests/unit/volume/v2/test_transfer_request.py4
-rw-r--r--openstackclient/tests/unit/volume/v2/test_type.py4
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume.py5
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_backup.py4
116 files changed, 2723 insertions, 258 deletions
diff --git a/openstackclient/tests/functional/compute/v2/test_agent.py b/openstackclient/tests/functional/compute/v2/test_agent.py
index 1a112e82..25d8c868 100644
--- a/openstackclient/tests/functional/compute/v2/test_agent.py
+++ b/openstackclient/tests/functional/compute/v2/test_agent.py
@@ -21,10 +21,10 @@ class ComputeAgentTests(base.TestCase):
# Generate two different md5hash
MD5HASH1 = hashlib.md5()
- MD5HASH1.update('agent_1')
+ MD5HASH1.update('agent_1'.encode('utf-8'))
MD5HASH1 = MD5HASH1.hexdigest()
MD5HASH2 = hashlib.md5()
- MD5HASH2.update('agent_2')
+ MD5HASH2.update('agent_2'.encode('utf-8'))
MD5HASH2 = MD5HASH2.hexdigest()
def test_compute_agent_delete(self):
diff --git a/openstackclient/tests/functional/compute/v2/test_aggregate.py b/openstackclient/tests/functional/compute/v2/test_aggregate.py
index 8a082e82..1de53099 100644
--- a/openstackclient/tests/functional/compute/v2/test_aggregate.py
+++ b/openstackclient/tests/functional/compute/v2/test_aggregate.py
@@ -11,7 +11,6 @@
# under the License.
import json
-import time
import uuid
from openstackclient.tests.functional import base
@@ -20,35 +19,14 @@ from openstackclient.tests.functional import base
class AggregateTests(base.TestCase):
"""Functional tests for aggregate"""
- @classmethod
- def wait_for_status(cls, check_type, check_name, desired_status,
- wait=120, interval=5, failures=None):
- current_status = "notset"
- if failures is None:
- failures = ['error']
- total_sleep = 0
- while total_sleep < wait:
- output = json.loads(cls.openstack(
- check_type + ' show -f json ' + check_name))
- current_status = output['name']
- if (current_status == desired_status):
- print('{} {} now has status {}'
- .format(check_type, check_name, current_status))
- return
- print('Checking {} {} Waiting for {} current status: {}'
- .format(check_type, check_name,
- desired_status, current_status))
- if current_status in failures:
- raise Exception(
- 'Current status {} of {} {} is one of failures {}'
- .format(current_status, check_type, check_name, failures))
- time.sleep(interval)
- total_sleep += interval
- cls.assertOutput(desired_status, current_status)
-
def test_aggregate_crud(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
+ self.addCleanup(
+ self.openstack,
+ 'aggregate delete ' + name1,
+ fail_ok=True,
+ )
cmd_output = json.loads(self.openstack(
'aggregate create -f json ' +
'--zone nova ' +
@@ -67,14 +45,16 @@ class AggregateTests(base.TestCase):
'a',
cmd_output['properties']
)
- self.wait_for_status('aggregate', name1, name1)
+ cmd_output = json.loads(self.openstack(
+ 'aggregate show -f json ' + name1))
+ self.assertEqual(name1, cmd_output['name'])
+
+ name2 = uuid.uuid4().hex
self.addCleanup(
self.openstack,
- 'aggregate delete ' + name1,
+ 'aggregate delete ' + name2,
fail_ok=True,
)
-
- name2 = uuid.uuid4().hex
cmd_output = json.loads(self.openstack(
'aggregate create -f json ' +
'--zone external ' +
@@ -88,15 +68,17 @@ class AggregateTests(base.TestCase):
'external',
cmd_output['availability_zone']
)
- self.wait_for_status('aggregate', name2, name2)
+ cmd_output = json.loads(self.openstack(
+ 'aggregate show -f json ' + name2))
+ self.assertEqual(name2, cmd_output['name'])
+
+ # Test aggregate set
+ name3 = uuid.uuid4().hex
self.addCleanup(
self.openstack,
- 'aggregate delete ' + name2,
+ 'aggregate delete ' + name3,
fail_ok=True,
)
-
- # Test aggregate set
- name3 = uuid.uuid4().hex
raw_output = self.openstack(
'aggregate set ' +
'--name ' + name3 + ' ' +
@@ -106,12 +88,6 @@ class AggregateTests(base.TestCase):
name1
)
self.assertOutput('', raw_output)
- self.wait_for_status('aggregate', name3, name3)
- self.addCleanup(
- self.openstack,
- 'aggregate delete ' + name3,
- fail_ok=True,
- )
cmd_output = json.loads(self.openstack(
'aggregate show -f json ' +
@@ -198,11 +174,11 @@ class AggregateTests(base.TestCase):
self.skipTest("Skip aggregates in a Nova cells v1 configuration")
name = uuid.uuid4().hex
+ self.addCleanup(self.openstack, 'aggregate delete ' + name)
self.openstack(
'aggregate create ' +
name
)
- self.addCleanup(self.openstack, 'aggregate delete ' + name)
# Test add host
cmd_output = json.loads(self.openstack(
diff --git a/openstackclient/tests/functional/compute/v2/test_keypair.py b/openstackclient/tests/functional/compute/v2/test_keypair.py
index 9a88e66f..42f334a4 100644
--- a/openstackclient/tests/functional/compute/v2/test_keypair.py
+++ b/openstackclient/tests/functional/compute/v2/test_keypair.py
@@ -88,7 +88,7 @@ class KeypairTests(KeypairBase):
1) Create keypair with given public key
2) Delete keypair
"""
- with tempfile.NamedTemporaryFile() as f:
+ with tempfile.NamedTemporaryFile(mode='w+') as f:
f.write(self.PUBLIC_KEY)
f.flush()
@@ -108,7 +108,7 @@ class KeypairTests(KeypairBase):
1) Create keypair with private key file
2) Delete keypair
"""
- with tempfile.NamedTemporaryFile() as f:
+ with tempfile.NamedTemporaryFile(mode='w+') as f:
cmd_output = json.loads(self.openstack(
'keypair create -f json --private-key %s tmpkey' % f.name,
))
diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py
index 2bca70d0..6e080e9b 100644
--- a/openstackclient/tests/functional/compute/v2/test_server.py
+++ b/openstackclient/tests/functional/compute/v2/test_server.py
@@ -63,6 +63,49 @@ class ServerTests(common.ComputeTestCase):
self.assertNotIn(name1, col_name)
self.assertIn(name2, col_name)
+ def test_server_list_with_marker_and_deleted(self):
+ """Test server list with deleted and marker"""
+ cmd_output = self.server_create(cleanup=False)
+ name1 = cmd_output['name']
+ cmd_output = self.server_create(cleanup=False)
+ name2 = cmd_output['name']
+ id2 = cmd_output['id']
+ self.wait_for_status(name1, "ACTIVE")
+ self.wait_for_status(name2, "ACTIVE")
+
+ # Test list --marker with ID
+ cmd_output = json.loads(self.openstack(
+ 'server list -f json --marker ' + id2
+ ))
+ col_name = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, col_name)
+
+ # Test list --marker with Name
+ cmd_output = json.loads(self.openstack(
+ 'server list -f json --marker ' + name2
+ ))
+ col_name = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, col_name)
+
+ self.openstack('server delete --wait ' + name1)
+ self.openstack('server delete --wait ' + name2)
+
+ # Test list --deleted --marker with ID
+ cmd_output = json.loads(self.openstack(
+ 'server list -f json --deleted --marker ' + id2
+ ))
+ col_name = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, col_name)
+
+ # Test list --deleted --marker with Name
+ try:
+ cmd_output = json.loads(self.openstack(
+ 'server list -f json --deleted --marker ' + name2
+ ))
+ except exceptions.CommandFailed as e:
+ self.assertIn('marker [%s] not found (HTTP 400)' % (name2),
+ e.stderr.decode('utf-8'))
+
def test_server_list_with_changes_before(self):
"""Test server list.
diff --git a/openstackclient/tests/functional/identity/v2/common.py b/openstackclient/tests/functional/identity/v2/common.py
index f4bc10bd..43c0cbf2 100644
--- a/openstackclient/tests/functional/identity/v2/common.py
+++ b/openstackclient/tests/functional/identity/v2/common.py
@@ -11,6 +11,7 @@
# under the License.
import os
+import unittest
import fixtures
from tempest.lib.common.utils import data_utils
@@ -62,7 +63,7 @@ class IdentityTests(base.TestCase):
# TODO(dtroyer): Actually determine if Identity v2 admin is
# enabled in the target cloud. Tuens out OSC
# doesn't make this easy as it should (yet).
- raise cls.skipException('No Identity v2 admin endpoint?')
+ raise unittest.case.SkipTest('No Identity v2 admin endpoint?')
@classmethod
def tearDownClass(cls):
diff --git a/openstackclient/tests/functional/identity/v3/common.py b/openstackclient/tests/functional/identity/v3/common.py
index 43b416aa..a5edd9a5 100644
--- a/openstackclient/tests/functional/identity/v3/common.py
+++ b/openstackclient/tests/functional/identity/v3/common.py
@@ -33,7 +33,7 @@ class IdentityTests(base.TestCase):
'password_expires_at']
PROJECT_FIELDS = ['description', 'id', 'domain_id', 'is_domain',
'enabled', 'name', 'parent_id']
- ROLE_FIELDS = ['id', 'name', 'domain_id']
+ ROLE_FIELDS = ['id', 'name', 'domain_id', 'description']
SERVICE_FIELDS = ['id', 'enabled', 'name', 'type', 'description']
REGION_FIELDS = ['description', 'enabled', 'parent_region', 'region']
ENDPOINT_FIELDS = ['id', 'region', 'region_id', 'service_id',
@@ -360,7 +360,7 @@ class IdentityTests(base.TestCase):
def _extract_value_from_items(self, key, items):
for d in items:
- for k, v in d.iteritems():
+ for k, v in d.items():
if k == key:
return v
diff --git a/openstackclient/tests/functional/identity/v3/test_role.py b/openstackclient/tests/functional/identity/v3/test_role.py
index 38bfff71..3954c4e3 100644
--- a/openstackclient/tests/functional/identity/v3/test_role.py
+++ b/openstackclient/tests/functional/identity/v3/test_role.py
@@ -20,6 +20,21 @@ class RoleTests(common.IdentityTests):
def test_role_create(self):
self._create_dummy_role()
+ def test_role_create_with_description(self):
+ role_name = data_utils.rand_name('TestRole')
+ description = data_utils.rand_name('description')
+ raw_output = self.openstack(
+ 'role create '
+ '--description %(description)s '
+ '%(name)s' % {'description': description,
+ 'name': role_name})
+ role = self.parse_show_as_object(raw_output)
+ self.addCleanup(self.openstack, 'role delete %s' % role['id'])
+ items = self.parse_show(raw_output)
+ self.assert_show_fields(items, self.ROLE_FIELDS)
+ self.assertEqual(description, role['description'])
+ return role_name
+
def test_role_delete(self):
role_name = self._create_dummy_role(add_clean_up=False)
raw_output = self.openstack('role delete %s' % role_name)
@@ -47,6 +62,16 @@ class RoleTests(common.IdentityTests):
role = self.parse_show_as_object(raw_output)
self.assertEqual(new_role_name, role['name'])
+ def test_role_set_description(self):
+ role_name = self._create_dummy_role()
+ description = data_utils.rand_name("NewDescription")
+ raw_output = self.openstack('role set --description %s %s'
+ % (description, role_name))
+ self.assertEqual(0, len(raw_output))
+ raw_output = self.openstack('role show %s' % role_name)
+ role = self.parse_show_as_object(raw_output)
+ self.assertEqual(description, role['description'])
+
def test_role_add(self):
role_name = self._create_dummy_role()
username = self._create_dummy_user()
diff --git a/openstackclient/tests/functional/object/v1/test_object.py b/openstackclient/tests/functional/object/v1/test_object.py
index 226ef8ad..b3f23e52 100644
--- a/openstackclient/tests/functional/object/v1/test_object.py
+++ b/openstackclient/tests/functional/object/v1/test_object.py
@@ -33,7 +33,7 @@ class ObjectTests(common.ObjectStoreTests):
self.skipTest("No object-store service present")
def test_object(self):
- with tempfile.NamedTemporaryFile() as f:
+ with tempfile.NamedTemporaryFile(mode='w+') as f:
f.write('test content')
f.flush()
self._test_object(f.name)
diff --git a/openstackclient/tests/functional/volume/v3/test_qos.py b/openstackclient/tests/functional/volume/v3/test_qos.py
index a6290fc5..fdfa6827 100644
--- a/openstackclient/tests/functional/volume/v3/test_qos.py
+++ b/openstackclient/tests/functional/volume/v3/test_qos.py
@@ -10,9 +10,209 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstackclient.tests.functional.volume.v2 import test_qos as v2
+import json
+import uuid
+
from openstackclient.tests.functional.volume.v3 import common
-class QosTests(common.BaseVolumeTests, v2.QosTests):
+class QosTests(common.BaseVolumeTests):
"""Functional tests for volume qos. """
+
+ def test_volume_qos_create_delete_list(self):
+ """Test create, list, delete multiple"""
+ name1 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume qos create -f json ' +
+ name1
+ ))
+ self.assertEqual(
+ name1,
+ cmd_output['name']
+ )
+
+ name2 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume qos create -f json ' +
+ name2
+ ))
+ self.assertEqual(
+ name2,
+ cmd_output['name']
+ )
+
+ # Test list
+ cmd_output = json.loads(self.openstack(
+ 'volume qos list -f json'
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, names)
+ self.assertIn(name2, names)
+
+ # Test delete multiple
+ del_output = self.openstack('volume qos delete ' + name1 + ' ' + name2)
+ self.assertOutput('', del_output)
+
+ def test_volume_qos_set_show_unset(self):
+ """Tests create volume qos, set, unset, show, delete"""
+
+ name = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume qos create -f json ' +
+ '--consumer front-end '
+ '--property Alpha=a ' +
+ name
+ ))
+ self.addCleanup(self.openstack, 'volume qos delete ' + name)
+ self.assertEqual(
+ name,
+ cmd_output['name']
+ )
+
+ self.assertEqual(
+ "front-end",
+ cmd_output['consumer']
+ )
+ self.assertEqual(
+ {'Alpha': 'a'},
+ cmd_output['properties']
+ )
+
+ # Test volume qos set
+ raw_output = self.openstack(
+ 'volume qos set ' +
+ '--property Alpha=c ' +
+ '--property Beta=b ' +
+ name,
+ )
+ self.assertOutput('', raw_output)
+
+ # Test volume qos show
+ cmd_output = json.loads(self.openstack(
+ 'volume qos show -f json ' +
+ name
+ ))
+ self.assertEqual(
+ name,
+ cmd_output['name']
+ )
+ self.assertEqual(
+ {'Alpha': 'c', 'Beta': 'b'},
+ cmd_output['properties']
+ )
+
+ # Test volume qos unset
+ raw_output = self.openstack(
+ 'volume qos unset ' +
+ '--property Alpha ' +
+ name,
+ )
+ self.assertOutput('', raw_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'volume qos show -f json ' +
+ name
+ ))
+ self.assertEqual(
+ name,
+ cmd_output['name']
+ )
+ self.assertEqual(
+ {'Beta': 'b'},
+ cmd_output['properties']
+ )
+
+ def test_volume_qos_asso_disasso(self):
+ """Tests associate and disassociate qos with volume type"""
+ vol_type1 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume type create -f json ' +
+ vol_type1
+ ))
+ self.assertEqual(
+ vol_type1,
+ cmd_output['name']
+ )
+ self.addCleanup(self.openstack, 'volume type delete ' + vol_type1)
+
+ vol_type2 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume type create -f json ' +
+ vol_type2
+ ))
+ self.assertEqual(
+ vol_type2,
+ cmd_output['name']
+ )
+ self.addCleanup(self.openstack, 'volume type delete ' + vol_type2)
+
+ name = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume qos create -f json ' +
+ name
+ ))
+ self.assertEqual(
+ name,
+ cmd_output['name']
+ )
+ self.addCleanup(self.openstack, 'volume qos delete ' + name)
+
+ # Test associate
+ raw_output = self.openstack(
+ 'volume qos associate ' +
+ name + ' ' + vol_type1
+ )
+ self.assertOutput('', raw_output)
+ raw_output = self.openstack(
+ 'volume qos associate ' +
+ name + ' ' + vol_type2
+ )
+ self.assertOutput('', raw_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'volume qos show -f json ' +
+ name
+ ))
+ types = cmd_output["associations"]
+ self.assertIn(vol_type1, types)
+ self.assertIn(vol_type2, types)
+
+ # Test disassociate
+ raw_output = self.openstack(
+ 'volume qos disassociate ' +
+ '--volume-type ' + vol_type1 +
+ ' ' + name
+ )
+ self.assertOutput('', raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume qos show -f json ' +
+ name
+ ))
+ types = cmd_output["associations"]
+ self.assertNotIn(vol_type1, types)
+ self.assertIn(vol_type2, types)
+
+ # Test disassociate --all
+ raw_output = self.openstack(
+ 'volume qos associate ' +
+ name + ' ' + vol_type1
+ )
+ self.assertOutput('', raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume qos show -f json ' +
+ name
+ ))
+ types = cmd_output["associations"]
+ self.assertIn(vol_type1, types)
+ self.assertIn(vol_type2, types)
+
+ raw_output = self.openstack(
+ 'volume qos disassociate ' +
+ '--all ' + name
+ )
+ self.assertOutput('', raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume qos show -f json ' +
+ name
+ ))
+ self.assertNotIn("associations", cmd_output.keys())
diff --git a/openstackclient/tests/functional/volume/v3/test_transfer_request.py b/openstackclient/tests/functional/volume/v3/test_transfer_request.py
index f16dfafa..1bbfedc9 100644
--- a/openstackclient/tests/functional/volume/v3/test_transfer_request.py
+++ b/openstackclient/tests/functional/volume/v3/test_transfer_request.py
@@ -10,12 +10,112 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstackclient.tests.functional.volume.v2 import test_transfer_request \
- as v2
+import json
+import uuid
+
from openstackclient.tests.functional.volume.v3 import common
-class TransferRequestTests(common.BaseVolumeTests, v2.TransferRequestTests):
+class TransferRequestTests(common.BaseVolumeTests):
"""Functional tests for transfer request. """
API_VERSION = '3'
+
+ def test_volume_transfer_request_accept(self):
+ volume_name = uuid.uuid4().hex
+ xfer_name = uuid.uuid4().hex
+
+ # create a volume
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--size 1 ' +
+ volume_name
+ ))
+ self.assertEqual(volume_name, cmd_output['name'])
+ self.addCleanup(
+ self.openstack,
+ '--os-volume-api-version ' + self.API_VERSION + ' ' +
+ 'volume delete ' +
+ volume_name
+ )
+ self.wait_for_status("volume", volume_name, "available")
+
+ # create volume transfer request for the volume
+ # and get the auth_key of the new transfer request
+ cmd_output = json.loads(self.openstack(
+ '--os-volume-api-version ' + self.API_VERSION + ' ' +
+ 'volume transfer request create -f json ' +
+ ' --name ' + xfer_name + ' ' +
+ volume_name
+ ))
+ self.assertEqual(xfer_name, cmd_output['name'])
+ xfer_id = cmd_output['id']
+ auth_key = cmd_output['auth_key']
+ self.assertTrue(auth_key)
+ self.wait_for_status("volume", volume_name, "awaiting-transfer")
+
+ # accept the volume transfer request
+ cmd_output = json.loads(self.openstack(
+ '--os-volume-api-version ' + self.API_VERSION + ' ' +
+ 'volume transfer request accept -f json ' +
+ '--auth-key ' + auth_key + ' ' +
+ xfer_id
+ ))
+ self.assertEqual(xfer_name, cmd_output['name'])
+ self.wait_for_status("volume", volume_name, "available")
+
+ def test_volume_transfer_request_list_show(self):
+ volume_name = uuid.uuid4().hex
+ xfer_name = uuid.uuid4().hex
+
+ # create a volume
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--size 1 ' +
+ volume_name
+ ))
+ self.assertEqual(volume_name, cmd_output['name'])
+ self.addCleanup(
+ self.openstack,
+ '--os-volume-api-version ' + self.API_VERSION + ' ' +
+ 'volume delete ' +
+ volume_name
+ )
+ self.wait_for_status("volume", volume_name, "available")
+
+ cmd_output = json.loads(self.openstack(
+ '--os-volume-api-version ' + self.API_VERSION + ' ' +
+ 'volume transfer request create -f json ' +
+ ' --name ' + xfer_name + ' ' +
+ volume_name
+ ))
+ self.assertEqual(xfer_name, cmd_output['name'])
+ xfer_id = cmd_output['id']
+ auth_key = cmd_output['auth_key']
+ self.assertTrue(auth_key)
+ self.wait_for_status("volume", volume_name, "awaiting-transfer")
+
+ cmd_output = json.loads(self.openstack(
+ '--os-volume-api-version ' + self.API_VERSION + ' ' +
+ 'volume transfer request list -f json'
+ ))
+ self.assertIn(xfer_name, [req['Name'] for req in cmd_output])
+
+ cmd_output = json.loads(self.openstack(
+ '--os-volume-api-version ' + self.API_VERSION + ' ' +
+ 'volume transfer request show -f json ' +
+ xfer_id
+ ))
+ self.assertEqual(xfer_name, cmd_output['name'])
+
+ # NOTE(dtroyer): We need to delete the transfer request to allow the
+ # volume to be deleted. The addCleanup() route does
+ # not have a mechanism to wait for the volume status
+ # to become 'available' before attempting to delete
+ # the volume.
+ cmd_output = self.openstack(
+ '--os-volume-api-version ' + self.API_VERSION + ' ' +
+ 'volume transfer request delete ' +
+ xfer_id
+ )
+ self.wait_for_status("volume", volume_name, "available")
diff --git a/openstackclient/tests/functional/volume/v3/test_volume.py b/openstackclient/tests/functional/volume/v3/test_volume.py
index 283b830f..6635167d 100644
--- a/openstackclient/tests/functional/volume/v3/test_volume.py
+++ b/openstackclient/tests/functional/volume/v3/test_volume.py
@@ -10,9 +10,273 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstackclient.tests.functional.volume.v2 import test_volume as v2
+import json
+import uuid
+
from openstackclient.tests.functional.volume.v3 import common
-class VolumeTests(common.BaseVolumeTests, v2.VolumeTests):
+class VolumeTests(common.BaseVolumeTests):
"""Functional tests for volume. """
+
+ def test_volume_delete(self):
+ """Test create, delete multiple"""
+ name1 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--size 1 ' +
+ name1
+ ))
+ self.assertEqual(
+ 1,
+ cmd_output["size"],
+ )
+
+ name2 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--size 2 ' +
+ name2
+ ))
+ self.assertEqual(
+ 2,
+ cmd_output["size"],
+ )
+
+ self.wait_for_status("volume", name1, "available")
+ self.wait_for_status("volume", name2, "available")
+ del_output = self.openstack('volume delete ' + name1 + ' ' + name2)
+ self.assertOutput('', del_output)
+
+ def test_volume_list(self):
+ """Test create, list filter"""
+ name1 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--size 1 ' +
+ name1
+ ))
+ self.addCleanup(self.openstack, 'volume delete ' + name1)
+ self.assertEqual(
+ 1,
+ cmd_output["size"],
+ )
+ self.wait_for_status("volume", name1, "available")
+
+ name2 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--size 2 ' +
+ name2
+ ))
+ self.addCleanup(self.openstack, 'volume delete ' + name2)
+ self.assertEqual(
+ 2,
+ cmd_output["size"],
+ )
+ self.wait_for_status("volume", name2, "available")
+ raw_output = self.openstack(
+ 'volume set ' +
+ '--state error ' +
+ name2
+ )
+ self.assertOutput('', raw_output)
+
+ # Test list --long
+ cmd_output = json.loads(self.openstack(
+ 'volume list -f json ' +
+ '--long'
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, names)
+ self.assertIn(name2, names)
+
+ # Test list --status
+ cmd_output = json.loads(self.openstack(
+ 'volume list -f json ' +
+ '--status error'
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertNotIn(name1, names)
+ self.assertIn(name2, names)
+
+ # TODO(qiangjiahui): Add project option to filter tests when we can
+ # specify volume with project
+
+ def test_volume_set_and_unset(self):
+ """Tests create volume, set, unset, show, delete"""
+ name = uuid.uuid4().hex
+ new_name = name + "_"
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--size 1 ' +
+ '--description aaaa ' +
+ '--property Alpha=a ' +
+ name
+ ))
+ self.addCleanup(self.openstack, 'volume delete ' + new_name)
+ self.assertEqual(
+ name,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ 1,
+ cmd_output["size"],
+ )
+ self.assertEqual(
+ 'aaaa',
+ cmd_output["description"],
+ )
+ self.assertEqual(
+ {'Alpha': 'a'},
+ cmd_output["properties"],
+ )
+ self.assertEqual(
+ 'false',
+ cmd_output["bootable"],
+ )
+ self.wait_for_status("volume", name, "available")
+
+ # Test volume set
+ raw_output = self.openstack(
+ 'volume set ' +
+ '--name ' + new_name +
+ ' --size 2 ' +
+ '--description bbbb ' +
+ '--no-property ' +
+ '--property Beta=b ' +
+ '--property Gamma=c ' +
+ '--image-property a=b ' +
+ '--image-property c=d ' +
+ '--bootable ' +
+ name,
+ )
+ self.assertOutput('', raw_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'volume show -f json ' +
+ new_name
+ ))
+ self.assertEqual(
+ new_name,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ 2,
+ cmd_output["size"],
+ )
+ self.assertEqual(
+ 'bbbb',
+ cmd_output["description"],
+ )
+ self.assertEqual(
+ {'Beta': 'b', 'Gamma': 'c'},
+ cmd_output["properties"],
+ )
+ self.assertEqual(
+ {'a': 'b', 'c': 'd'},
+ cmd_output["volume_image_metadata"],
+ )
+ self.assertEqual(
+ 'true',
+ cmd_output["bootable"],
+ )
+
+ # Test volume unset
+ raw_output = self.openstack(
+ 'volume unset ' +
+ '--property Beta ' +
+ '--image-property a ' +
+ new_name,
+ )
+ self.assertOutput('', raw_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'volume show -f json ' +
+ new_name
+ ))
+ self.assertEqual(
+ {'Gamma': 'c'},
+ cmd_output["properties"],
+ )
+ self.assertEqual(
+ {'c': 'd'},
+ cmd_output["volume_image_metadata"],
+ )
+
+ def test_volume_snapshot(self):
+ """Tests volume create from snapshot"""
+
+ volume_name = uuid.uuid4().hex
+ snapshot_name = uuid.uuid4().hex
+ # Make a snapshot
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--size 1 ' +
+ volume_name
+ ))
+ self.wait_for_status("volume", volume_name, "available")
+ self.assertEqual(
+ volume_name,
+ cmd_output["name"],
+ )
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot create -f json ' +
+ snapshot_name +
+ ' --volume ' + volume_name
+ ))
+ self.wait_for_status("volume snapshot", snapshot_name, "available")
+
+ name = uuid.uuid4().hex
+ # Create volume from snapshot
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--snapshot ' + snapshot_name +
+ ' ' + name
+ ))
+ self.addCleanup(self.openstack, 'volume delete ' + name)
+ self.addCleanup(self.openstack, 'volume delete ' + volume_name)
+ self.assertEqual(
+ name,
+ cmd_output["name"],
+ )
+ self.wait_for_status("volume", name, "available")
+
+ # Delete snapshot
+ raw_output = self.openstack(
+ 'volume snapshot delete ' + snapshot_name)
+ self.assertOutput('', raw_output)
+ # Deleting snapshot may take time. If volume snapshot still exists when
+ # a parent volume delete is requested, the volume deletion will fail.
+ self.wait_for_delete('volume snapshot', snapshot_name)
+
+ def test_volume_list_backward_compatibility(self):
+ """Test backward compatibility of list command"""
+ name1 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume create -f json ' +
+ '--size 1 ' +
+ name1
+ ))
+ self.addCleanup(self.openstack, 'volume delete ' + name1)
+ self.assertEqual(
+ 1,
+ cmd_output["size"],
+ )
+ self.wait_for_status("volume", name1, "available")
+
+ # Test list -c "Display Name"
+ cmd_output = json.loads(self.openstack(
+ 'volume list -f json ' +
+ '-c "Display Name"'
+ ))
+ for each_volume in cmd_output:
+ self.assertIn('Display Name', each_volume)
+
+ # Test list -c "Name"
+ cmd_output = json.loads(self.openstack(
+ 'volume list -f json ' +
+ '-c "Name"'
+ ))
+ for each_volume in cmd_output:
+ self.assertIn('Name', each_volume)
diff --git a/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py b/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py
index 28eee6d2..edfdafb6 100644
--- a/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py
+++ b/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py
@@ -10,9 +10,245 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstackclient.tests.functional.volume.v2 import test_volume_snapshot as v2 # noqa
+import json
+import uuid
+
from openstackclient.tests.functional.volume.v3 import common
-class VolumeSnapshotTests(common.BaseVolumeTests, v2.VolumeSnapshotTests):
+class VolumeSnapshotTests(common.BaseVolumeTests):
"""Functional tests for volume snapshot. """
+
+ VOLLY = uuid.uuid4().hex
+
+ @classmethod
+ def setUpClass(cls):
+ super(VolumeSnapshotTests, cls).setUpClass()
+ # create a volume for all tests to create snapshot
+ cmd_output = json.loads(cls.openstack(
+ 'volume create -f json ' +
+ '--size 1 ' +
+ cls.VOLLY
+ ))
+ cls.wait_for_status('volume', cls.VOLLY, 'available')
+ cls.VOLUME_ID = cmd_output['id']
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ cls.wait_for_status('volume', cls.VOLLY, 'available')
+ raw_output = cls.openstack(
+ 'volume delete --force ' + cls.VOLLY)
+ cls.assertOutput('', raw_output)
+ finally:
+ super(VolumeSnapshotTests, cls).tearDownClass()
+
+ def test_volume_snapshot_delete(self):
+ """Test create, delete multiple"""
+ name1 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot create -f json ' +
+ name1 +
+ ' --volume ' + self.VOLLY
+ ))
+ self.assertEqual(
+ name1,
+ cmd_output["name"],
+ )
+
+ name2 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot create -f json ' +
+ name2 +
+ ' --volume ' + self.VOLLY
+ ))
+ self.assertEqual(
+ name2,
+ cmd_output["name"],
+ )
+
+ self.wait_for_status('volume snapshot', name1, 'available')
+ self.wait_for_status('volume snapshot', name2, 'available')
+
+ del_output = self.openstack(
+ 'volume snapshot delete ' + name1 + ' ' + name2)
+ self.assertOutput('', del_output)
+ self.wait_for_delete('volume snapshot', name1)
+ self.wait_for_delete('volume snapshot', name2)
+
+ def test_volume_snapshot_list(self):
+ """Test create, list filter"""
+ name1 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot create -f json ' +
+ name1 +
+ ' --volume ' + self.VOLLY
+ ))
+ self.addCleanup(self.wait_for_delete, 'volume snapshot', name1)
+ self.addCleanup(self.openstack, 'volume snapshot delete ' + name1)
+ self.assertEqual(
+ name1,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ self.VOLUME_ID,
+ cmd_output["volume_id"],
+ )
+ self.assertEqual(
+ 1,
+ cmd_output["size"],
+ )
+ self.wait_for_status('volume snapshot', name1, 'available')
+
+ name2 = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot create -f json ' +
+ name2 +
+ ' --volume ' + self.VOLLY
+ ))
+ self.addCleanup(self.wait_for_delete, 'volume snapshot', name2)
+ self.addCleanup(self.openstack, 'volume snapshot delete ' + name2)
+ self.assertEqual(
+ name2,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ self.VOLUME_ID,
+ cmd_output["volume_id"],
+ )
+ self.assertEqual(
+ 1,
+ cmd_output["size"],
+ )
+ self.wait_for_status('volume snapshot', name2, 'available')
+ raw_output = self.openstack(
+ 'volume snapshot set ' +
+ '--state error ' +
+ name2
+ )
+ self.assertOutput('', raw_output)
+
+ # Test list --long, --status
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot list -f json ' +
+ '--long ' +
+ '--status error'
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertNotIn(name1, names)
+ self.assertIn(name2, names)
+
+ # Test list --volume
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot list -f json ' +
+ '--volume ' + self.VOLLY
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, names)
+ self.assertIn(name2, names)
+
+ # Test list --name
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot list -f json ' +
+ '--name ' + name1
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, names)
+ self.assertNotIn(name2, names)
+
+ def test_volume_snapshot_set(self):
+ """Test create, set, unset, show, delete volume snapshot"""
+ name = uuid.uuid4().hex
+ new_name = name + "_"
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot create -f json ' +
+ '--volume ' + self.VOLLY +
+ ' --description aaaa ' +
+ '--property Alpha=a ' +
+ name
+ ))
+ self.addCleanup(self.wait_for_delete, 'volume snapshot', new_name)
+ self.addCleanup(self.openstack, 'volume snapshot delete ' + new_name)
+ self.assertEqual(
+ name,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ 1,
+ cmd_output["size"],
+ )
+ self.assertEqual(
+ 'aaaa',
+ cmd_output["description"],
+ )
+ self.assertEqual(
+ {'Alpha': 'a'},
+ cmd_output["properties"],
+ )
+ self.wait_for_status('volume snapshot', name, 'available')
+
+ # Test volume snapshot set
+ raw_output = self.openstack(
+ 'volume snapshot set ' +
+ '--name ' + new_name +
+ ' --description bbbb ' +
+ '--property Alpha=c ' +
+ '--property Beta=b ' +
+ name,
+ )
+ self.assertOutput('', raw_output)
+
+ # Show snapshot set result
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot show -f json ' +
+ new_name
+ ))
+ self.assertEqual(
+ new_name,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ 1,
+ cmd_output["size"],
+ )
+ self.assertEqual(
+ 'bbbb',
+ cmd_output["description"],
+ )
+ self.assertEqual(
+ {'Alpha': 'c', 'Beta': 'b'},
+ cmd_output["properties"],
+ )
+
+ # Test volume snapshot unset
+ raw_output = self.openstack(
+ 'volume snapshot unset ' +
+ '--property Alpha ' +
+ new_name,
+ )
+ self.assertOutput('', raw_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot show -f json ' +
+ new_name
+ ))
+ self.assertEqual(
+ {'Beta': 'b'},
+ cmd_output["properties"],
+ )
+
+ # Test volume snapshot set --no-property
+ raw_output = self.openstack(
+ 'volume snapshot set ' +
+ '--no-property ' +
+ new_name,
+ )
+ self.assertOutput('', raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume snapshot show -f json ' +
+ new_name
+ ))
+ self.assertNotIn(
+ {'Beta': 'b'},
+ cmd_output["properties"],
+ )
diff --git a/openstackclient/tests/functional/volume/v3/test_volume_type.py b/openstackclient/tests/functional/volume/v3/test_volume_type.py
index eb66515e..79d40969 100644
--- a/openstackclient/tests/functional/volume/v3/test_volume_type.py
+++ b/openstackclient/tests/functional/volume/v3/test_volume_type.py
@@ -10,9 +10,229 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstackclient.tests.functional.volume.v2 import test_volume_type as v2
+import json
+import time
+import uuid
+
from openstackclient.tests.functional.volume.v3 import common
-class VolumeTypeTests(common.BaseVolumeTests, v2.VolumeTypeTests):
+class VolumeTypeTests(common.BaseVolumeTests):
"""Functional tests for volume type. """
+
+ def test_volume_type_create_list(self):
+ name = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume type create -f json --private ' +
+ name,
+ ))
+ self.addCleanup(
+ self.openstack,
+ 'volume type delete ' + name,
+ )
+ self.assertEqual(name, cmd_output['name'])
+
+ cmd_output = json.loads(self.openstack(
+ 'volume type show -f json %s' % name
+ ))
+ self.assertEqual(name, cmd_output['name'])
+
+ cmd_output = json.loads(self.openstack('volume type list -f json'))
+ self.assertIn(name, [t['Name'] for t in cmd_output])
+
+ cmd_output = json.loads(self.openstack(
+ 'volume type list -f json --default'
+ ))
+ self.assertEqual(1, len(cmd_output))
+ self.assertEqual('lvmdriver-1', cmd_output[0]['Name'])
+
+ def test_volume_type_set_unset_properties(self):
+ name = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume type create -f json --private ' +
+ name,
+ ))
+ self.addCleanup(
+ self.openstack,
+ 'volume type delete ' + name
+ )
+ self.assertEqual(name, cmd_output['name'])
+
+ raw_output = self.openstack(
+ 'volume type set --property a=b --property c=d %s' % name
+ )
+ self.assertEqual("", raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume type show -f json %s' % name
+ ))
+ self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
+
+ raw_output = self.openstack(
+ 'volume type unset --property a %s' % name
+ )
+ self.assertEqual("", raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume type show -f json %s' % name
+ ))
+ self.assertEqual({'c': 'd'}, cmd_output['properties'])
+
+ def test_volume_type_set_unset_multiple_properties(self):
+ name = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume type create -f json --private ' +
+ name,
+ ))
+ self.addCleanup(
+ self.openstack,
+ 'volume type delete ' + name
+ )
+ self.assertEqual(name, cmd_output['name'])
+
+ raw_output = self.openstack(
+ 'volume type set --property a=b --property c=d %s' % name
+ )
+ self.assertEqual("", raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume type show -f json %s' % name
+ ))
+ self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
+
+ raw_output = self.openstack(
+ 'volume type unset --property a --property c %s' % name
+ )
+ self.assertEqual("", raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume type show -f json %s' % name
+ ))
+ self.assertEqual({}, cmd_output['properties'])
+
+ def test_volume_type_set_unset_project(self):
+ name = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'volume type create -f json --private ' +
+ name,
+ ))
+ self.addCleanup(
+ self.openstack,
+ 'volume type delete ' + name
+ )
+ self.assertEqual(name, cmd_output['name'])
+
+ raw_output = self.openstack(
+ 'volume type set --project admin %s' % name
+ )
+ self.assertEqual("", raw_output)
+
+ raw_output = self.openstack(
+ 'volume type unset --project admin %s' % name
+ )
+ self.assertEqual("", raw_output)
+
+ def test_multi_delete(self):
+ vol_type1 = uuid.uuid4().hex
+ vol_type2 = uuid.uuid4().hex
+ self.openstack('volume type create %s' % vol_type1)
+ time.sleep(5)
+ self.openstack('volume type create %s' % vol_type2)
+ time.sleep(5)
+ cmd = 'volume type delete %s %s' % (vol_type1, vol_type2)
+ raw_output = self.openstack(cmd)
+ self.assertOutput('', raw_output)
+
+ # NOTE: Add some basic funtional tests with the old format to
+ # make sure the command works properly, need to change
+ # these to new test format when beef up all tests for
+ # volume tye commands.
+ def test_encryption_type(self):
+ name = uuid.uuid4().hex
+ encryption_type = uuid.uuid4().hex
+ # test create new encryption type
+ cmd_output = json.loads(self.openstack(
+ 'volume type create -f json '
+ '--encryption-provider LuksEncryptor '
+ '--encryption-cipher aes-xts-plain64 '
+ '--encryption-key-size 128 '
+ '--encryption-control-location front-end ' +
+ encryption_type))
+ expected = {'provider': 'LuksEncryptor',
+ 'cipher': 'aes-xts-plain64',
+ 'key_size': 128,
+ 'control_location': 'front-end'}
+ for attr, value in expected.items():
+ self.assertEqual(value, cmd_output['encryption'][attr])
+ # test show encryption type
+ cmd_output = json.loads(self.openstack(
+ 'volume type show -f json --encryption-type ' + encryption_type))
+ expected = {'provider': 'LuksEncryptor',
+ 'cipher': 'aes-xts-plain64',
+ 'key_size': 128,
+ 'control_location': 'front-end'}
+ for attr, value in expected.items():
+ self.assertEqual(value, cmd_output['encryption'][attr])
+ # test list encryption type
+ cmd_output = json.loads(self.openstack(
+ 'volume type list -f json --encryption-type'))
+ encryption_output = [t['Encryption'] for t in cmd_output
+ if t['Name'] == encryption_type][0]
+ expected = {'provider': 'LuksEncryptor',
+ 'cipher': 'aes-xts-plain64',
+ 'key_size': 128,
+ 'control_location': 'front-end'}
+ for attr, value in expected.items():
+ self.assertEqual(value, encryption_output[attr])
+ # test set existing encryption type
+ raw_output = self.openstack(
+ 'volume type set '
+ '--encryption-key-size 256 '
+ '--encryption-control-location back-end ' +
+ encryption_type)
+ self.assertEqual('', raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume type show -f json --encryption-type ' + encryption_type))
+ expected = {'provider': 'LuksEncryptor',
+ 'cipher': 'aes-xts-plain64',
+ 'key_size': 256,
+ 'control_location': 'back-end'}
+ for attr, value in expected.items():
+ self.assertEqual(value, cmd_output['encryption'][attr])
+ # test set new encryption type
+ cmd_output = json.loads(self.openstack(
+ 'volume type create -f json --private ' +
+ name,
+ ))
+ self.addCleanup(
+ self.openstack,
+ 'volume type delete ' + name,
+ )
+ self.assertEqual(name, cmd_output['name'])
+
+ raw_output = self.openstack(
+ 'volume type set '
+ '--encryption-provider LuksEncryptor '
+ '--encryption-cipher aes-xts-plain64 '
+ '--encryption-key-size 128 '
+ '--encryption-control-location front-end ' +
+ name)
+ self.assertEqual('', raw_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'volume type show -f json --encryption-type ' + name
+ ))
+ expected = {'provider': 'LuksEncryptor',
+ 'cipher': 'aes-xts-plain64',
+ 'key_size': 128,
+ 'control_location': 'front-end'}
+ for attr, value in expected.items():
+ self.assertEqual(value, cmd_output['encryption'][attr])
+ # test unset encryption type
+ raw_output = self.openstack(
+ 'volume type unset --encryption-type ' + name
+ )
+ self.assertEqual('', raw_output)
+ cmd_output = json.loads(self.openstack(
+ 'volume type show -f json --encryption-type ' + name
+ ))
+ self.assertEqual({}, cmd_output['encryption'])
+ # test delete encryption type
+ raw_output = self.openstack('volume type delete ' + encryption_type)
+ self.assertEqual('', raw_output)
diff --git a/openstackclient/tests/unit/api/test_object_store_v1.py b/openstackclient/tests/unit/api/test_object_store_v1.py
index 74b62493..96c68d5a 100644
--- a/openstackclient/tests/unit/api/test_object_store_v1.py
+++ b/openstackclient/tests/unit/api/test_object_store_v1.py
@@ -13,7 +13,7 @@
"""Object Store v1 API Library Tests"""
-import mock
+from unittest import mock
from keystoneauth1 import session
from requests_mock.contrib import fixture
@@ -151,12 +151,14 @@ class TestContainer(TestObjectAPIv1):
'X-Container-Meta-Owner': FAKE_ACCOUNT,
'x-container-object-count': '1',
'x-container-bytes-used': '577',
+ 'x-storage-policy': 'o1--sr-r3'
}
resp = {
'account': FAKE_ACCOUNT,
'container': 'qaz',
'object_count': '1',
'bytes_used': '577',
+ 'storage_policy': 'o1--sr-r3',
'properties': {'Owner': FAKE_ACCOUNT},
}
self.requests_mock.register_uri(
diff --git a/openstackclient/tests/unit/common/test_availability_zone.py b/openstackclient/tests/unit/common/test_availability_zone.py
index 6c7adc43..8733b510 100644
--- a/openstackclient/tests/unit/common/test_availability_zone.py
+++ b/openstackclient/tests/unit/common/test_availability_zone.py
@@ -11,9 +11,7 @@
# under the License.
#
-import mock
-
-import six
+from unittest import mock
from openstackclient.common import availability_zone
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
@@ -31,8 +29,8 @@ def _build_compute_az_datalist(compute_az, long_datalist=False):
'available',
)
else:
- for host, services in six.iteritems(compute_az.hosts):
- for service, state in six.iteritems(services):
+ for host, services in compute_az.hosts.items():
+ for service, state in services.items():
datalist += (
compute_az.zoneName,
'available',
diff --git a/openstackclient/tests/unit/common/test_command.py b/openstackclient/tests/unit/common/test_command.py
index 6ddb7c12..4fde5301 100644
--- a/openstackclient/tests/unit/common/test_command.py
+++ b/openstackclient/tests/unit/common/test_command.py
@@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
+from unittest import mock
from osc_lib.command import command
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/common/test_configuration.py b/openstackclient/tests/unit/common/test_configuration.py
index e10522b9..bdd3debf 100644
--- a/openstackclient/tests/unit/common/test_configuration.py
+++ b/openstackclient/tests/unit/common/test_configuration.py
@@ -11,7 +11,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.common import configuration
from openstackclient.tests.unit import fakes
diff --git a/openstackclient/tests/unit/common/test_extension.py b/openstackclient/tests/unit/common/test_extension.py
index eefa814c..5093cbbb 100644
--- a/openstackclient/tests/unit/common/test_extension.py
+++ b/openstackclient/tests/unit/common/test_extension.py
@@ -11,7 +11,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.common import extension
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
@@ -36,13 +36,9 @@ class TestExtension(utils.TestCommand):
self.identity_extensions_mock = identity_client.extensions
self.identity_extensions_mock.reset_mock()
- compute_client = compute_fakes.FakeComputev2Client(
- endpoint=fakes.AUTH_URL,
- token=fakes.AUTH_TOKEN,
- )
- self.app.client_manager.compute = compute_client
- compute_client.list_extensions = mock.Mock()
- self.compute_extensions_mock = compute_client.list_extensions
+ sdk_connection = mock.Mock()
+ self.app.client_manager.sdk_connection = sdk_connection
+ self.compute_extensions_mock = sdk_connection.compute.extensions
self.compute_extensions_mock.reset_mock()
volume_client = volume_fakes.FakeVolumeClient(
@@ -80,8 +76,7 @@ class TestExtensionList(TestExtension):
self.identity_extensions_mock.list.return_value = [
self.identity_extension]
- self.compute_extensions_mock.show_all.return_value = [
- self.compute_extension]
+ self.compute_extensions_mock.return_value = [self.compute_extension]
self.volume_extensions_mock.show_all.return_value = [
self.volume_extension]
self.network_extensions_mock.return_value = [self.network_extension]
@@ -131,7 +126,7 @@ class TestExtensionList(TestExtension):
)
self._test_extension_list_helper(arglist, verifylist, datalist)
self.identity_extensions_mock.list.assert_called_with()
- self.compute_extensions_mock.show_all.assert_called_with()
+ self.compute_extensions_mock.assert_called_with()
self.volume_extensions_mock.show_all.assert_called_with()
self.network_extensions_mock.assert_called_with()
@@ -178,7 +173,7 @@ class TestExtensionList(TestExtension):
)
self._test_extension_list_helper(arglist, verifylist, datalist, True)
self.identity_extensions_mock.list.assert_called_with()
- self.compute_extensions_mock.show_all.assert_called_with()
+ self.compute_extensions_mock.assert_called_with()
self.volume_extensions_mock.show_all.assert_called_with()
self.network_extensions_mock.assert_called_with()
@@ -248,7 +243,7 @@ class TestExtensionList(TestExtension):
self.compute_extension.description,
), )
self._test_extension_list_helper(arglist, verifylist, datalist)
- self.compute_extensions_mock.show_all.assert_called_with()
+ self.compute_extensions_mock.assert_called_with()
def test_extension_list_compute_and_network(self):
arglist = [
@@ -272,7 +267,7 @@ class TestExtensionList(TestExtension):
),
)
self._test_extension_list_helper(arglist, verifylist, datalist)
- self.compute_extensions_mock.show_all.assert_called_with()
+ self.compute_extensions_mock.assert_called_with()
self.network_extensions_mock.assert_called_with()
def test_extension_list_volume(self):
diff --git a/openstackclient/tests/unit/common/test_logs.py b/openstackclient/tests/unit/common/test_logs.py
index 421234d6..0e710561 100644
--- a/openstackclient/tests/unit/common/test_logs.py
+++ b/openstackclient/tests/unit/common/test_logs.py
@@ -15,8 +15,7 @@
# or Jun 2017.
import logging
-
-import mock
+from unittest import mock
from osc_lib import logs
diff --git a/openstackclient/tests/unit/common/test_module.py b/openstackclient/tests/unit/common/test_module.py
index 2491d639..d2e8293f 100644
--- a/openstackclient/tests/unit/common/test_module.py
+++ b/openstackclient/tests/unit/common/test_module.py
@@ -15,7 +15,7 @@
"""Test module module"""
-import mock
+from unittest import mock
from openstackclient.common import module as osc_module
from openstackclient.tests.unit import fakes
diff --git a/openstackclient/tests/unit/common/test_project_purge.py b/openstackclient/tests/unit/common/test_project_purge.py
index 6e8ce188..adc48ce2 100644
--- a/openstackclient/tests/unit/common/test_project_purge.py
+++ b/openstackclient/tests/unit/common/test_project_purge.py
@@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
+from unittest import mock
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/common/test_quota.py b/openstackclient/tests/unit/common/test_quota.py
index 297452a2..bd59ca77 100644
--- a/openstackclient/tests/unit/common/test_quota.py
+++ b/openstackclient/tests/unit/common/test_quota.py
@@ -11,8 +11,8 @@
# under the License.
import copy
+from unittest import mock
-import mock
from osc_lib import exceptions
from openstackclient.common import quota
diff --git a/openstackclient/tests/unit/compute/v2/fakes.py b/openstackclient/tests/unit/compute/v2/fakes.py
index 7357e143..6e12f735 100644
--- a/openstackclient/tests/unit/compute/v2/fakes.py
+++ b/openstackclient/tests/unit/compute/v2/fakes.py
@@ -14,9 +14,9 @@
#
import copy
+from unittest import mock
import uuid
-import mock
from novaclient import api_versions
from openstackclient.api import compute_v2
diff --git a/openstackclient/tests/unit/compute/v2/test_agent.py b/openstackclient/tests/unit/compute/v2/test_agent.py
index 169940e2..c6d4f2b6 100644
--- a/openstackclient/tests/unit/compute/v2/test_agent.py
+++ b/openstackclient/tests/unit/compute/v2/test_agent.py
@@ -13,8 +13,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/compute/v2/test_aggregate.py b/openstackclient/tests/unit/compute/v2/test_aggregate.py
index 0937047c..cd0c1525 100644
--- a/openstackclient/tests/unit/compute/v2/test_aggregate.py
+++ b/openstackclient/tests/unit/compute/v2/test_aggregate.py
@@ -13,8 +13,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/compute/v2/test_console.py b/openstackclient/tests/unit/compute/v2/test_console.py
index 3c708aae..99a14f04 100644
--- a/openstackclient/tests/unit/compute/v2/test_console.py
+++ b/openstackclient/tests/unit/compute/v2/test_console.py
@@ -13,7 +13,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.compute.v2 import console
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
diff --git a/openstackclient/tests/unit/compute/v2/test_flavor.py b/openstackclient/tests/unit/compute/v2/test_flavor.py
index a112fc1f..fe7ce174 100644
--- a/openstackclient/tests/unit/compute/v2/test_flavor.py
+++ b/openstackclient/tests/unit/compute/v2/test_flavor.py
@@ -13,8 +13,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
import novaclient
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/compute/v2/test_host.py b/openstackclient/tests/unit/compute/v2/test_host.py
index 244da413..4e1b5ad1 100644
--- a/openstackclient/tests/unit/compute/v2/test_host.py
+++ b/openstackclient/tests/unit/compute/v2/test_host.py
@@ -13,7 +13,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.compute.v2 import host
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
diff --git a/openstackclient/tests/unit/compute/v2/test_keypair.py b/openstackclient/tests/unit/compute/v2/test_keypair.py
index 0e5fb143..1f3f56f9 100644
--- a/openstackclient/tests/unit/compute/v2/test_keypair.py
+++ b/openstackclient/tests/unit/compute/v2/test_keypair.py
@@ -13,10 +13,10 @@
# under the License.
#
+from unittest import mock
+from unittest.mock import call
import uuid
-import mock
-from mock import call
from osc_lib import exceptions
from osc_lib import utils
diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py
index 0793116a..27eefd85 100644
--- a/openstackclient/tests/unit/compute/v2/test_server.py
+++ b/openstackclient/tests/unit/compute/v2/test_server.py
@@ -16,9 +16,9 @@ import argparse
import collections
import copy
import getpass
+from unittest import mock
+from unittest.mock import call
-import mock
-from mock import call
from novaclient import api_versions
from openstack import exceptions as sdk_exceptions
from osc_lib import exceptions
@@ -43,6 +43,10 @@ class TestServer(compute_fakes.TestComputev2):
self.servers_mock = self.app.client_manager.compute.servers
self.servers_mock.reset_mock()
+ # Get a shortcut to the compute client volumeManager Mock
+ self.servers_volumes_mock = self.app.client_manager.compute.volumes
+ self.servers_volumes_mock.reset_mock()
+
# Get a shortcut to the compute client FlavorManager Mock
self.flavors_mock = self.app.client_manager.compute.flavors
self.flavors_mock.reset_mock()
@@ -109,6 +113,10 @@ class TestServer(compute_fakes.TestComputev2):
version = self.app.client_manager.compute.api_version
if version >= api_versions.APIVersion('2.73'):
method.assert_called_with(reason=None)
+ elif method_name == 'unshelve':
+ version = self.app.client_manager.compute.api_version
+ if version >= api_versions.APIVersion('2.77'):
+ method.assert_called_with(availability_zone=None)
else:
method.assert_called_with()
else:
@@ -453,6 +461,175 @@ class TestServerAddPort(TestServer):
self.find_port.assert_not_called()
+class TestServerVolume(TestServer):
+
+ def setUp(self):
+ super(TestServerVolume, self).setUp()
+
+ self.volume = volume_fakes.FakeVolume.create_one_volume()
+ self.volumes_mock.get.return_value = self.volume
+
+ self.methods = {
+ 'create_server_volume': None,
+ }
+
+ # Get the command object to test
+ self.cmd = server.AddServerVolume(self.app, None)
+
+ def test_server_add_volume(self):
+ servers = self.setup_servers_mock(count=1)
+ arglist = [
+ '--device', '/dev/sdb',
+ servers[0].id,
+ self.volume.id,
+ ]
+ verifylist = [
+ ('server', servers[0].id),
+ ('volume', self.volume.id),
+ ('device', '/dev/sdb'),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.servers_volumes_mock.create_server_volume.assert_called_once_with(
+ servers[0].id, self.volume.id, device='/dev/sdb')
+ self.assertIsNone(result)
+
+
+class TestServerVolumeV279(TestServerVolume):
+
+ def test_server_add_volume_with_enable_delete_on_termination(self):
+ self.app.client_manager.compute.api_version = api_versions.APIVersion(
+ '2.79')
+
+ servers = self.setup_servers_mock(count=1)
+ arglist = [
+ '--enable-delete-on-termination',
+ '--device', '/dev/sdb',
+ servers[0].id,
+ self.volume.id,
+ ]
+
+ verifylist = [
+ ('server', servers[0].id),
+ ('volume', self.volume.id),
+ ('device', '/dev/sdb'),
+ ('enable_delete_on_termination', True),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.servers_volumes_mock.create_server_volume.assert_called_once_with(
+ servers[0].id, self.volume.id,
+ device='/dev/sdb', delete_on_termination=True)
+ self.assertIsNone(result)
+
+ def test_server_add_volume_with_disable_delete_on_termination(self):
+ self.app.client_manager.compute.api_version = api_versions.APIVersion(
+ '2.79')
+
+ servers = self.setup_servers_mock(count=1)
+ arglist = [
+ '--disable-delete-on-termination',
+ '--device', '/dev/sdb',
+ servers[0].id,
+ self.volume.id,
+ ]
+
+ verifylist = [
+ ('server', servers[0].id),
+ ('volume', self.volume.id),
+ ('device', '/dev/sdb'),
+ ('disable_delete_on_termination', True),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.servers_volumes_mock.create_server_volume.assert_called_once_with(
+ servers[0].id, self.volume.id,
+ device='/dev/sdb', delete_on_termination=False)
+ self.assertIsNone(result)
+
+ def test_server_add_volume_with_enable_delete_on_termination_pre_v279(
+ self):
+ self.app.client_manager.compute.api_version = api_versions.APIVersion(
+ '2.78')
+
+ servers = self.setup_servers_mock(count=1)
+ arglist = [
+ servers[0].id,
+ self.volume.id,
+ '--enable-delete-on-termination',
+ ]
+ verifylist = [
+ ('server', servers[0].id),
+ ('volume', self.volume.id),
+ ('enable_delete_on_termination', True),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ ex = self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action,
+ parsed_args)
+ self.assertIn('--os-compute-api-version 2.79 or greater is required',
+ str(ex))
+
+ def test_server_add_volume_with_disable_delete_on_termination_pre_v279(
+ self):
+ self.app.client_manager.compute.api_version = api_versions.APIVersion(
+ '2.78')
+
+ servers = self.setup_servers_mock(count=1)
+ arglist = [
+ servers[0].id,
+ self.volume.id,
+ '--disable-delete-on-termination',
+ ]
+ verifylist = [
+ ('server', servers[0].id),
+ ('volume', self.volume.id),
+ ('disable_delete_on_termination', True),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ ex = self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action,
+ parsed_args)
+ self.assertIn('--os-compute-api-version 2.79 or greater is required',
+ str(ex))
+
+ def test_server_add_volume_with_disable_and_enable_delete_on_termination(
+ self):
+ self.app.client_manager.compute.api_version = api_versions.APIVersion(
+ '2.79')
+
+ servers = self.setup_servers_mock(count=1)
+ arglist = [
+ '--enable-delete-on-termination',
+ '--disable-delete-on-termination',
+ '--device', '/dev/sdb',
+ servers[0].id,
+ self.volume.id,
+ ]
+
+ verifylist = [
+ ('server', servers[0].id),
+ ('volume', self.volume.id),
+ ('device', '/dev/sdb'),
+ ('enable_delete_on_termination', True),
+ ('disable_delete_on_termination', True),
+ ]
+ ex = self.assertRaises(utils.ParserException,
+ self.check_parser,
+ self.cmd, arglist, verifylist)
+ self.assertIn('argument --disable-delete-on-termination: not allowed '
+ 'with argument --enable-delete-on-termination', str(ex))
+
+
class TestServerAddNetwork(TestServer):
def setUp(self):
@@ -683,7 +860,7 @@ class TestServerCreate(TestServer):
('key_name', 'keyname'),
('property', {'Beta': 'b'}),
('security_group', ['securitygroup']),
- ('hint', ['a=b', 'a=c']),
+ ('hint', {'a': ['b', 'c']}),
('config_drive', False),
('server_name', self.new_server.name),
]
@@ -1883,6 +2060,29 @@ class TestServerCreate(TestServer):
self.cmd.take_action,
parsed_args)
+ def test_server_create_invalid_hint(self):
+ # Not a key-value pair
+ arglist = [
+ '--image', 'image1',
+ '--flavor', 'flavor1',
+ '--hint', 'a0cf03a5-d921-4877-bb5c-86d26cf818e1',
+ self.new_server.name,
+ ]
+ self.assertRaises(argparse.ArgumentTypeError,
+ self.check_parser,
+ self.cmd, arglist, [])
+
+ # Empty key
+ arglist = [
+ '--image', 'image1',
+ '--flavor', 'flavor1',
+ '--hint', '=a0cf03a5-d921-4877-bb5c-86d26cf818e1',
+ self.new_server.name,
+ ]
+ self.assertRaises(argparse.ArgumentTypeError,
+ self.check_parser,
+ self.cmd, arglist, [])
+
def test_server_create_with_description_api_newer(self):
# Description is supported for nova api version 2.19 or above
@@ -4777,6 +4977,56 @@ class TestServerUnshelve(TestServer):
def test_unshelve_multi_servers(self):
self.run_method_with_servers('unshelve', 3)
+ def test_unshelve_server_with_specified_az(self):
+ server = compute_fakes.FakeServer.create_one_server()
+ arglist = [
+ server.id,
+ '--availability-zone', "foo-az",
+ ]
+ verifylist = [
+ ('availability_zone', "foo-az"),
+ ('server', [server.id])
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ ex = self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action,
+ parsed_args)
+ self.assertIn(
+ '--os-compute-api-version 2.77 or greater is required', str(ex))
+
+
+class TestServerUnshelveV277(TestServerUnshelve):
+
+ def setUp(self):
+ super(TestServerUnshelveV277, self).setUp()
+
+ self.server = compute_fakes.FakeServer.create_one_server(
+ methods=self.methods)
+
+ # This is the return value for utils.find_resource()
+ self.servers_mock.get.return_value = self.server
+
+ # Get the command object to test
+ self.cmd = server.UnshelveServer(self.app, None)
+
+ def test_specified_az_to_unshelve_with_v277(self):
+ self.app.client_manager.compute.api_version = api_versions.APIVersion(
+ '2.77')
+
+ arglist = [
+ '--availability-zone', "foo-az",
+ self.server.id,
+ ]
+ verifylist = [
+ ('availability_zone', "foo-az"),
+ ('server', [self.server.id])
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.cmd.take_action(parsed_args)
+ self.servers_mock.get.assert_called_with(self.server.id)
+ self.server.unshelve.assert_called_with(availability_zone="foo-az")
+
class TestServerGeneral(TestServer):
OLD = {
diff --git a/openstackclient/tests/unit/compute/v2/test_server_backup.py b/openstackclient/tests/unit/compute/v2/test_server_backup.py
index 24a94531..7dd459d8 100644
--- a/openstackclient/tests/unit/compute/v2/test_server_backup.py
+++ b/openstackclient/tests/unit/compute/v2/test_server_backup.py
@@ -11,7 +11,7 @@
# under the License.
#
-import mock
+from unittest import mock
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/compute/v2/test_server_group.py b/openstackclient/tests/unit/compute/v2/test_server_group.py
index dc924e24..9cd876ea 100644
--- a/openstackclient/tests/unit/compute/v2/test_server_group.py
+++ b/openstackclient/tests/unit/compute/v2/test_server_group.py
@@ -13,7 +13,7 @@
# under the License.
#
-import mock
+from unittest import mock
from osc_lib import exceptions
from osc_lib import utils
diff --git a/openstackclient/tests/unit/compute/v2/test_server_image.py b/openstackclient/tests/unit/compute/v2/test_server_image.py
index 02e43129..f9d7b10e 100644
--- a/openstackclient/tests/unit/compute/v2/test_server_image.py
+++ b/openstackclient/tests/unit/compute/v2/test_server_image.py
@@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
#
-import mock
+from unittest import mock
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/compute/v2/test_service.py b/openstackclient/tests/unit/compute/v2/test_service.py
index 0d663b2e..7a036833 100644
--- a/openstackclient/tests/unit/compute/v2/test_service.py
+++ b/openstackclient/tests/unit/compute/v2/test_service.py
@@ -13,8 +13,9 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
+
from novaclient import api_versions
from osc_lib import exceptions
import six
diff --git a/openstackclient/tests/unit/compute/v2/test_usage.py b/openstackclient/tests/unit/compute/v2/test_usage.py
index 76dcc963..c0871025 100644
--- a/openstackclient/tests/unit/compute/v2/test_usage.py
+++ b/openstackclient/tests/unit/compute/v2/test_usage.py
@@ -12,8 +12,8 @@
#
import datetime
+from unittest import mock
-import mock
from novaclient import api_versions
from openstackclient.compute.v2 import usage
diff --git a/openstackclient/tests/unit/fakes.py b/openstackclient/tests/unit/fakes.py
index bca457e4..e5476f06 100644
--- a/openstackclient/tests/unit/fakes.py
+++ b/openstackclient/tests/unit/fakes.py
@@ -15,9 +15,9 @@
import json
import sys
+from unittest import mock
from keystoneauth1 import fixture
-import mock
import requests
import six
@@ -200,7 +200,7 @@ class FakeResource(object):
self._loaded = loaded
def _add_details(self, info):
- for (k, v) in six.iteritems(info):
+ for (k, v) in info.items():
setattr(self, k, v)
def _add_methods(self, methods):
@@ -211,7 +211,7 @@ class FakeResource(object):
@value. When users access the attribute with (), @value will be
returned, which looks like a function call.
"""
- for (name, ret) in six.iteritems(methods):
+ for (name, ret) in methods.items():
method = mock.Mock(return_value=ret)
setattr(self, name, method)
diff --git a/openstackclient/tests/unit/identity/v2_0/fakes.py b/openstackclient/tests/unit/identity/v2_0/fakes.py
index 5db94222..bd76a784 100644
--- a/openstackclient/tests/unit/identity/v2_0/fakes.py
+++ b/openstackclient/tests/unit/identity/v2_0/fakes.py
@@ -14,11 +14,11 @@
#
import copy
+from unittest import mock
import uuid
from keystoneauth1 import access
from keystoneauth1 import fixture
-import mock
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit import utils
diff --git a/openstackclient/tests/unit/identity/v2_0/test_catalog.py b/openstackclient/tests/unit/identity/v2_0/test_catalog.py
index 362dec08..17355074 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_catalog.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_catalog.py
@@ -11,7 +11,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.identity.v2_0 import catalog
from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
diff --git a/openstackclient/tests/unit/identity/v2_0/test_project.py b/openstackclient/tests/unit/identity/v2_0/test_project.py
index 7af7b394..cd8c825d 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_project.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_project.py
@@ -13,7 +13,7 @@
# under the License.
#
-import mock
+from unittest import mock
from keystoneauth1 import exceptions as ks_exc
from osc_lib.cli import format_columns
diff --git a/openstackclient/tests/unit/identity/v2_0/test_role.py b/openstackclient/tests/unit/identity/v2_0/test_role.py
index 643d77f6..423884d9 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_role.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_role.py
@@ -13,7 +13,7 @@
# under the License.
#
-import mock
+from unittest import mock
from keystoneauth1 import exceptions as ks_exc
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py b/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py
index 733fda6c..3e1231aa 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py
@@ -12,8 +12,8 @@
#
import copy
+from unittest import mock
-import mock
from osc_lib import exceptions
from openstackclient.identity.v2_0 import role_assignment
diff --git a/openstackclient/tests/unit/identity/v2_0/test_token.py b/openstackclient/tests/unit/identity/v2_0/test_token.py
index dd7f4f4a..c079ce67 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_token.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_token.py
@@ -13,7 +13,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.identity.v2_0 import token
from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
diff --git a/openstackclient/tests/unit/identity/v2_0/test_user.py b/openstackclient/tests/unit/identity/v2_0/test_user.py
index 0a0d4b36..4308b05d 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_user.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_user.py
@@ -13,7 +13,7 @@
# under the License.
#
-import mock
+from unittest import mock
from keystoneauth1 import exceptions as ks_exc
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/identity/v3/fakes.py b/openstackclient/tests/unit/identity/v3/fakes.py
index e9ff0689..eb3ce2a3 100644
--- a/openstackclient/tests/unit/identity/v3/fakes.py
+++ b/openstackclient/tests/unit/identity/v3/fakes.py
@@ -15,11 +15,11 @@
import copy
import datetime
+from unittest import mock
import uuid
from keystoneauth1 import access
from keystoneauth1 import fixture
-import mock
from osc_lib.cli import format_columns
from openstackclient.tests.unit import fakes
@@ -176,6 +176,7 @@ ids_for_children = [PROJECT_WITH_GRANDPARENT['id']]
role_id = 'r1'
role_name = 'roller'
+role_description = 'role description'
ROLE = {
'id': role_id,
@@ -470,6 +471,14 @@ app_cred_description = 'app credential for testing'
app_cred_expires = datetime.datetime(2022, 1, 1, 0, 0)
app_cred_expires_str = app_cred_expires.strftime('%Y-%m-%dT%H:%M:%S%z')
app_cred_secret = 'moresecuresecret'
+app_cred_access_rules = (
+ '[{"path": "/v2.1/servers", "method": "GET", "service": "compute"}]'
+)
+app_cred_access_rules_path = '/tmp/access_rules.json'
+access_rule_id = 'access-rule-id'
+access_rule_service = 'compute'
+access_rule_path = '/v2.1/servers'
+access_rule_method = 'GET'
APP_CRED_BASIC = {
'id': app_cred_id,
'name': app_cred_name,
@@ -478,7 +487,8 @@ APP_CRED_BASIC = {
'description': None,
'expires_at': None,
'unrestricted': False,
- 'secret': app_cred_secret
+ 'secret': app_cred_secret,
+ 'access_rules': None
}
APP_CRED_OPTIONS = {
'id': app_cred_id,
@@ -488,7 +498,25 @@ APP_CRED_OPTIONS = {
'description': app_cred_description,
'expires_at': app_cred_expires_str,
'unrestricted': False,
- 'secret': app_cred_secret
+ 'secret': app_cred_secret,
+ 'access_rules': None,
+}
+ACCESS_RULE = {
+ 'id': access_rule_id,
+ 'service': access_rule_service,
+ 'path': access_rule_path,
+ 'method': access_rule_method,
+}
+APP_CRED_ACCESS_RULES = {
+ 'id': app_cred_id,
+ 'name': app_cred_name,
+ 'project_id': project_id,
+ 'roles': app_cred_role,
+ 'description': None,
+ 'expires_at': None,
+ 'unrestricted': False,
+ 'secret': app_cred_secret,
+ 'access_rules': app_cred_access_rules
}
registered_limit_id = 'registered-limit-id'
@@ -625,6 +653,8 @@ class FakeIdentityv3Client(object):
self.application_credentials = mock.Mock()
self.application_credentials.resource_class = fakes.FakeResource(None,
{})
+ self.access_rules = mock.Mock()
+ self.access_rules.resource_class = fakes.FakeResource(None, {})
self.inference_rules = mock.Mock()
self.inference_rules.resource_class = fakes.FakeResource(None, {})
self.registered_limits = mock.Mock()
diff --git a/openstackclient/tests/unit/identity/v3/test_access_rule.py b/openstackclient/tests/unit/identity/v3/test_access_rule.py
new file mode 100644
index 00000000..f8b6093a
--- /dev/null
+++ b/openstackclient/tests/unit/identity/v3/test_access_rule.py
@@ -0,0 +1,174 @@
+# Copyright 2019 SUSE LLC
+#
+# 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.
+#
+
+import copy
+
+import mock
+from osc_lib import exceptions
+from osc_lib import utils
+
+from openstackclient.identity.v3 import access_rule
+from openstackclient.tests.unit import fakes
+from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
+
+
+class TestAccessRule(identity_fakes.TestIdentityv3):
+
+ def setUp(self):
+ super(TestAccessRule, self).setUp()
+
+ identity_manager = self.app.client_manager.identity
+ self.access_rules_mock = identity_manager.access_rules
+ self.access_rules_mock.reset_mock()
+ self.roles_mock = identity_manager.roles
+ self.roles_mock.reset_mock()
+
+
+class TestAccessRuleDelete(TestAccessRule):
+
+ def setUp(self):
+ super(TestAccessRuleDelete, self).setUp()
+
+ # This is the return value for utils.find_resource()
+ self.access_rules_mock.get.return_value = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.ACCESS_RULE),
+ loaded=True,
+ )
+ self.access_rules_mock.delete.return_value = None
+
+ # Get the command object to test
+ self.cmd = access_rule.DeleteAccessRule(
+ self.app, None)
+
+ def test_access_rule_delete(self):
+ arglist = [
+ identity_fakes.access_rule_id,
+ ]
+ verifylist = [
+ ('access_rule', [identity_fakes.access_rule_id])
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.access_rules_mock.delete.assert_called_with(
+ identity_fakes.access_rule_id,
+ )
+ self.assertIsNone(result)
+
+ @mock.patch.object(utils, 'find_resource')
+ def test_delete_multi_access_rules_with_exception(self, find_mock):
+ find_mock.side_effect = [self.access_rules_mock.get.return_value,
+ exceptions.CommandError]
+ arglist = [
+ identity_fakes.access_rule_id,
+ 'nonexistent_access_rule',
+ ]
+ verifylist = [
+ ('access_rule', arglist),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ try:
+ self.cmd.take_action(parsed_args)
+ self.fail('CommandError should be raised.')
+ except exceptions.CommandError as e:
+ self.assertEqual('1 of 2 access rules failed to'
+ ' delete.', str(e))
+
+ find_mock.assert_any_call(self.access_rules_mock,
+ identity_fakes.access_rule_id)
+ find_mock.assert_any_call(self.access_rules_mock,
+ 'nonexistent_access_rule')
+
+ self.assertEqual(2, find_mock.call_count)
+ self.access_rules_mock.delete.assert_called_once_with(
+ identity_fakes.access_rule_id)
+
+
+class TestAccessRuleList(TestAccessRule):
+
+ def setUp(self):
+ super(TestAccessRuleList, self).setUp()
+
+ self.access_rules_mock.list.return_value = [
+ fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.ACCESS_RULE),
+ loaded=True,
+ ),
+ ]
+
+ # Get the command object to test
+ self.cmd = access_rule.ListAccessRule(self.app, None)
+
+ def test_access_rule_list(self):
+ arglist = []
+ verifylist = []
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.access_rules_mock.list.assert_called_with(user=None)
+
+ collist = ('ID', 'Service', 'Method', 'Path')
+ self.assertEqual(collist, columns)
+ datalist = ((
+ identity_fakes.access_rule_id,
+ identity_fakes.access_rule_service,
+ identity_fakes.access_rule_method,
+ identity_fakes.access_rule_path,
+ ), )
+ self.assertEqual(datalist, tuple(data))
+
+
+class TestAccessRuleShow(TestAccessRule):
+
+ def setUp(self):
+ super(TestAccessRuleShow, self).setUp()
+
+ self.access_rules_mock.get.return_value = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.ACCESS_RULE),
+ loaded=True,
+ )
+
+ # Get the command object to test
+ self.cmd = access_rule.ShowAccessRule(self.app, None)
+
+ def test_access_rule_show(self):
+ arglist = [
+ identity_fakes.access_rule_id,
+ ]
+ verifylist = [
+ ('access_rule', identity_fakes.access_rule_id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.access_rules_mock.get.assert_called_with(
+ identity_fakes.access_rule_id)
+
+ collist = ('id', 'method', 'path', 'service')
+ self.assertEqual(collist, columns)
+ datalist = (
+ identity_fakes.access_rule_id,
+ identity_fakes.access_rule_method,
+ identity_fakes.access_rule_path,
+ identity_fakes.access_rule_service,
+ )
+ self.assertEqual(datalist, data)
diff --git a/openstackclient/tests/unit/identity/v3/test_application_credential.py b/openstackclient/tests/unit/identity/v3/test_application_credential.py
index e7c8ede8..24bafc9f 100644
--- a/openstackclient/tests/unit/identity/v3/test_application_credential.py
+++ b/openstackclient/tests/unit/identity/v3/test_application_credential.py
@@ -14,8 +14,9 @@
#
import copy
+import json
+from unittest import mock
-import mock
from osc_lib import exceptions
from osc_lib import utils
@@ -79,18 +80,20 @@ class TestApplicationCredentialCreate(TestApplicationCredential):
'expires_at': None,
'description': None,
'unrestricted': False,
+ 'access_rules': None,
}
self.app_creds_mock.create.assert_called_with(
name,
**kwargs
)
- collist = ('description', 'expires_at', 'id', 'name', 'project_id',
- 'roles', 'secret', 'unrestricted')
+ collist = ('access_rules', 'description', 'expires_at', 'id', 'name',
+ 'project_id', 'roles', 'secret', 'unrestricted')
self.assertEqual(collist, columns)
datalist = (
None,
None,
+ None,
identity_fakes.app_cred_id,
identity_fakes.app_cred_name,
identity_fakes.project_id,
@@ -135,17 +138,19 @@ class TestApplicationCredentialCreate(TestApplicationCredential):
'roles': [identity_fakes.role_id],
'expires_at': identity_fakes.app_cred_expires,
'description': 'credential for testing',
- 'unrestricted': False
+ 'unrestricted': False,
+ 'access_rules': None,
}
self.app_creds_mock.create.assert_called_with(
name,
**kwargs
)
- collist = ('description', 'expires_at', 'id', 'name', 'project_id',
- 'roles', 'secret', 'unrestricted')
+ collist = ('access_rules', 'description', 'expires_at', 'id', 'name',
+ 'project_id', 'roles', 'secret', 'unrestricted')
self.assertEqual(collist, columns)
datalist = (
+ None,
identity_fakes.app_cred_description,
identity_fakes.app_cred_expires_str,
identity_fakes.app_cred_id,
@@ -157,6 +162,111 @@ class TestApplicationCredentialCreate(TestApplicationCredential):
)
self.assertEqual(datalist, data)
+ def test_application_credential_create_with_access_rules_string(self):
+ name = identity_fakes.app_cred_name
+ self.app_creds_mock.create.return_value = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.APP_CRED_ACCESS_RULES),
+ loaded=True,
+ )
+
+ arglist = [
+ name,
+ '--access-rules', identity_fakes.app_cred_access_rules,
+ ]
+ verifylist = [
+ ('name', identity_fakes.app_cred_name),
+ ('access_rules', identity_fakes.app_cred_access_rules),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'secret': None,
+ 'roles': [],
+ 'expires_at': None,
+ 'description': None,
+ 'unrestricted': False,
+ 'access_rules': json.loads(identity_fakes.app_cred_access_rules)
+ }
+ self.app_creds_mock.create.assert_called_with(
+ name,
+ **kwargs
+ )
+
+ collist = ('access_rules', 'description', 'expires_at', 'id', 'name',
+ 'project_id', 'roles', 'secret', 'unrestricted')
+ self.assertEqual(collist, columns)
+ datalist = (
+ identity_fakes.app_cred_access_rules,
+ None,
+ None,
+ identity_fakes.app_cred_id,
+ identity_fakes.app_cred_name,
+ identity_fakes.project_id,
+ identity_fakes.role_name,
+ identity_fakes.app_cred_secret,
+ False,
+ )
+ self.assertEqual(datalist, data)
+
+ @mock.patch('openstackclient.identity.v3.application_credential.json.load')
+ @mock.patch('openstackclient.identity.v3.application_credential.open')
+ def test_application_credential_create_with_access_rules_file(
+ self, _, mock_json_load):
+ mock_json_load.return_value = identity_fakes.app_cred_access_rules
+
+ name = identity_fakes.app_cred_name
+ self.app_creds_mock.create.return_value = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.APP_CRED_ACCESS_RULES),
+ loaded=True,
+ )
+
+ arglist = [
+ name,
+ '--access-rules', identity_fakes.app_cred_access_rules_path,
+ ]
+ verifylist = [
+ ('name', identity_fakes.app_cred_name),
+ ('access_rules', identity_fakes.app_cred_access_rules_path),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'secret': None,
+ 'roles': [],
+ 'expires_at': None,
+ 'description': None,
+ 'unrestricted': False,
+ 'access_rules': identity_fakes.app_cred_access_rules
+ }
+ self.app_creds_mock.create.assert_called_with(
+ name,
+ **kwargs
+ )
+
+ collist = ('access_rules', 'description', 'expires_at', 'id', 'name',
+ 'project_id', 'roles', 'secret', 'unrestricted')
+ self.assertEqual(collist, columns)
+ datalist = (
+ identity_fakes.app_cred_access_rules,
+ None,
+ None,
+ identity_fakes.app_cred_id,
+ identity_fakes.app_cred_name,
+ identity_fakes.project_id,
+ identity_fakes.role_name,
+ identity_fakes.app_cred_secret,
+ False,
+ )
+ self.assertEqual(datalist, data)
+
class TestApplicationCredentialDelete(TestApplicationCredential):
@@ -293,12 +403,13 @@ class TestApplicationCredentialShow(TestApplicationCredential):
self.app_creds_mock.get.assert_called_with(identity_fakes.app_cred_id)
- collist = ('description', 'expires_at', 'id', 'name', 'project_id',
- 'roles', 'secret', 'unrestricted')
+ collist = ('access_rules', 'description', 'expires_at', 'id', 'name',
+ 'project_id', 'roles', 'secret', 'unrestricted')
self.assertEqual(collist, columns)
datalist = (
None,
None,
+ None,
identity_fakes.app_cred_id,
identity_fakes.app_cred_name,
identity_fakes.project_id,
diff --git a/openstackclient/tests/unit/identity/v3/test_catalog.py b/openstackclient/tests/unit/identity/v3/test_catalog.py
index ba076dbd..3630ccb6 100644
--- a/openstackclient/tests/unit/identity/v3/test_catalog.py
+++ b/openstackclient/tests/unit/identity/v3/test_catalog.py
@@ -11,7 +11,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.identity.v3 import catalog
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
diff --git a/openstackclient/tests/unit/identity/v3/test_credential.py b/openstackclient/tests/unit/identity/v3/test_credential.py
index de0306dd..40596d58 100644
--- a/openstackclient/tests/unit/identity/v3/test_credential.py
+++ b/openstackclient/tests/unit/identity/v3/test_credential.py
@@ -10,8 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/identity/v3/test_endpoint_group.py b/openstackclient/tests/unit/identity/v3/test_endpoint_group.py
index 6e9da9c7..c081fa1f 100644
--- a/openstackclient/tests/unit/identity/v3/test_endpoint_group.py
+++ b/openstackclient/tests/unit/identity/v3/test_endpoint_group.py
@@ -11,7 +11,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.identity.v3 import endpoint_group
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
diff --git a/openstackclient/tests/unit/identity/v3/test_group.py b/openstackclient/tests/unit/identity/v3/test_group.py
index 81722631..04ba0dbe 100644
--- a/openstackclient/tests/unit/identity/v3/test_group.py
+++ b/openstackclient/tests/unit/identity/v3/test_group.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from keystoneauth1 import exceptions as ks_exc
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/identity/v3/test_identity_provider.py b/openstackclient/tests/unit/identity/v3/test_identity_provider.py
index 0163c6c8..a419a9bc 100644
--- a/openstackclient/tests/unit/identity/v3/test_identity_provider.py
+++ b/openstackclient/tests/unit/identity/v3/test_identity_provider.py
@@ -13,8 +13,7 @@
# under the License.
import copy
-
-import mock
+from unittest import mock
from openstackclient.identity.v3 import identity_provider
from openstackclient.tests.unit import fakes
diff --git a/openstackclient/tests/unit/identity/v3/test_mappings.py b/openstackclient/tests/unit/identity/v3/test_mappings.py
index 1d8e77d9..184bd2a2 100644
--- a/openstackclient/tests/unit/identity/v3/test_mappings.py
+++ b/openstackclient/tests/unit/identity/v3/test_mappings.py
@@ -13,8 +13,8 @@
# under the License.
import copy
+from unittest import mock
-import mock
from osc_lib import exceptions
from openstackclient.identity.v3 import mapping
diff --git a/openstackclient/tests/unit/identity/v3/test_project.py b/openstackclient/tests/unit/identity/v3/test_project.py
index 266da227..466bea18 100644
--- a/openstackclient/tests/unit/identity/v3/test_project.py
+++ b/openstackclient/tests/unit/identity/v3/test_project.py
@@ -13,8 +13,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
from osc_lib import utils
@@ -645,6 +645,28 @@ class TestProjectList(TestProject):
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
+ def test_project_list_parent(self):
+ self.parent = identity_fakes.FakeProject.create_one_project()
+ self.project = identity_fakes.FakeProject.create_one_project(
+ attrs={'domain_id': self.domain.id, 'parent_id': self.parent.id})
+
+ arglist = [
+ '--parent', self.parent.id,
+ ]
+ verifylist = [
+ ('parent', self.parent.id),
+ ]
+
+ self.projects_mock.get.return_value = self.parent
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+ self.projects_mock.list.assert_called_with(parent=self.parent.id)
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.datalist, tuple(data))
+
def test_project_list_sort(self):
self.projects_mock.list.return_value = self.projects
diff --git a/openstackclient/tests/unit/identity/v3/test_role.py b/openstackclient/tests/unit/identity/v3/test_role.py
index 99f3a2de..4278ab1c 100644
--- a/openstackclient/tests/unit/identity/v3/test_role.py
+++ b/openstackclient/tests/unit/identity/v3/test_role.py
@@ -14,8 +14,8 @@
#
import copy
+from unittest import mock
-import mock
from osc_lib import exceptions
from osc_lib import utils
@@ -332,6 +332,7 @@ class TestRoleCreate(TestRole):
kwargs = {
'domain': None,
'name': identity_fakes.role_name,
+ 'description': None,
}
# RoleManager.create(name=, domain=)
@@ -375,6 +376,7 @@ class TestRoleCreate(TestRole):
kwargs = {
'domain': identity_fakes.domain_id,
'name': identity_fakes.ROLE_2['name'],
+ 'description': None,
}
# RoleManager.create(name=, domain=)
@@ -391,6 +393,49 @@ class TestRoleCreate(TestRole):
)
self.assertEqual(datalist, data)
+ def test_role_create_with_description(self):
+
+ self.roles_mock.create.return_value = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.ROLE_2),
+ loaded=True,
+ )
+ arglist = [
+ '--description', identity_fakes.role_description,
+ identity_fakes.ROLE_2['name'],
+ ]
+ verifylist = [
+ ('description', identity_fakes.role_description),
+ ('name', identity_fakes.ROLE_2['name']),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'description': identity_fakes.role_description,
+ 'name': identity_fakes.ROLE_2['name'],
+ 'domain': None,
+ }
+
+ # RoleManager.create(name=, domain=)
+ self.roles_mock.create.assert_called_with(
+ **kwargs
+ )
+
+ collist = ('domain', 'id', 'name')
+ self.assertEqual(collist, columns)
+ datalist = (
+ 'd1',
+ identity_fakes.ROLE_2['id'],
+ identity_fakes.ROLE_2['name'],
+ )
+ self.assertEqual(datalist, data)
+
class TestRoleDelete(TestRole):
@@ -825,6 +870,7 @@ class TestRoleSet(TestRole):
# Set expected values
kwargs = {
'name': 'over',
+ 'description': None,
}
# RoleManager.update(role, name=)
self.roles_mock.update.assert_called_with(
@@ -856,6 +902,39 @@ class TestRoleSet(TestRole):
# Set expected values
kwargs = {
'name': 'over',
+ 'description': None,
+ }
+ # RoleManager.update(role, name=)
+ self.roles_mock.update.assert_called_with(
+ identity_fakes.ROLE_2['id'],
+ **kwargs
+ )
+ self.assertIsNone(result)
+
+ def test_role_set_description(self):
+ self.roles_mock.get.return_value = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.ROLE_2),
+ loaded=True,
+ )
+ arglist = [
+ '--name', 'over',
+ '--description', identity_fakes.role_description,
+ identity_fakes.ROLE_2['name'],
+ ]
+ verifylist = [
+ ('name', 'over'),
+ ('description', identity_fakes.role_description),
+ ('role', identity_fakes.ROLE_2['name']),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'name': 'over',
+ 'description': identity_fakes.role_description,
}
# RoleManager.update(role, name=)
self.roles_mock.update.assert_called_with(
diff --git a/openstackclient/tests/unit/identity/v3/test_role_assignment.py b/openstackclient/tests/unit/identity/v3/test_role_assignment.py
index bff6c56d..7d38d360 100644
--- a/openstackclient/tests/unit/identity/v3/test_role_assignment.py
+++ b/openstackclient/tests/unit/identity/v3/test_role_assignment.py
@@ -12,8 +12,7 @@
#
import copy
-
-import mock
+from unittest import mock
from openstackclient.identity.v3 import role_assignment
from openstackclient.tests.unit import fakes
diff --git a/openstackclient/tests/unit/identity/v3/test_token.py b/openstackclient/tests/unit/identity/v3/test_token.py
index 7321909f..adb491b3 100644
--- a/openstackclient/tests/unit/identity/v3/test_token.py
+++ b/openstackclient/tests/unit/identity/v3/test_token.py
@@ -13,7 +13,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.identity.v3 import token
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
diff --git a/openstackclient/tests/unit/identity/v3/test_trust.py b/openstackclient/tests/unit/identity/v3/test_trust.py
index 1355b908..d8cfc59f 100644
--- a/openstackclient/tests/unit/identity/v3/test_trust.py
+++ b/openstackclient/tests/unit/identity/v3/test_trust.py
@@ -12,8 +12,8 @@
#
import copy
+from unittest import mock
-import mock
from osc_lib import exceptions
from osc_lib import utils
diff --git a/openstackclient/tests/unit/identity/v3/test_user.py b/openstackclient/tests/unit/identity/v3/test_user.py
index 920ee950..4b14bca0 100644
--- a/openstackclient/tests/unit/identity/v3/test_user.py
+++ b/openstackclient/tests/unit/identity/v3/test_user.py
@@ -14,8 +14,8 @@
#
import contextlib
+from unittest import mock
-import mock
from osc_lib import exceptions
from osc_lib import utils
diff --git a/openstackclient/tests/unit/image/v1/fakes.py b/openstackclient/tests/unit/image/v1/fakes.py
index bbec00fc..de232235 100644
--- a/openstackclient/tests/unit/image/v1/fakes.py
+++ b/openstackclient/tests/unit/image/v1/fakes.py
@@ -14,10 +14,9 @@
#
import copy
+from unittest import mock
import uuid
-import mock
-
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit import utils
from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes
diff --git a/openstackclient/tests/unit/image/v1/test_image.py b/openstackclient/tests/unit/image/v1/test_image.py
index 0997d765..970b36c6 100644
--- a/openstackclient/tests/unit/image/v1/test_image.py
+++ b/openstackclient/tests/unit/image/v1/test_image.py
@@ -14,8 +14,7 @@
#
import copy
-
-import mock
+from unittest import mock
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/image/v2/fakes.py b/openstackclient/tests/unit/image/v2/fakes.py
index f69a2bc3..655ae341 100644
--- a/openstackclient/tests/unit/image/v2/fakes.py
+++ b/openstackclient/tests/unit/image/v2/fakes.py
@@ -15,10 +15,10 @@
import copy
import random
+from unittest import mock
import uuid
from glanceclient.v2 import schemas
-import mock
from osc_lib.cli import format_columns
import warlock
diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py
index 748a61aa..78d857e2 100644
--- a/openstackclient/tests/unit/image/v2/test_image.py
+++ b/openstackclient/tests/unit/image/v2/test_image.py
@@ -14,10 +14,10 @@
#
import copy
+from unittest import mock
from glanceclient.common import utils as glanceclient_utils
from glanceclient.v2 import schemas
-import mock
from osc_lib.cli import format_columns
from osc_lib import exceptions
import warlock
diff --git a/openstackclient/tests/unit/integ/cli/test_shell.py b/openstackclient/tests/unit/integ/cli/test_shell.py
index 25985171..0c98a129 100644
--- a/openstackclient/tests/unit/integ/cli/test_shell.py
+++ b/openstackclient/tests/unit/integ/cli/test_shell.py
@@ -11,9 +11,9 @@
# under the License.
import copy
+from unittest import mock
import fixtures
-import mock
from osc_lib.tests import utils as osc_lib_utils
from openstackclient import shell
diff --git a/openstackclient/tests/unit/network/test_common.py b/openstackclient/tests/unit/network/test_common.py
index 3a206878..cde321aa 100644
--- a/openstackclient/tests/unit/network/test_common.py
+++ b/openstackclient/tests/unit/network/test_common.py
@@ -12,8 +12,8 @@
#
import argparse
+from unittest import mock
-import mock
import openstack
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index 1519bd4b..a553f501 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -15,10 +15,9 @@ import argparse
import copy
from random import choice
from random import randint
+from unittest import mock
import uuid
-import mock
-
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes_v3
from openstackclient.tests.unit import utils
@@ -639,6 +638,7 @@ class FakePort(object):
'security_group_ids': [],
'status': 'ACTIVE',
'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ 'qos_network_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
'tags': [],
'uplink_status_propagation': False,
@@ -1816,3 +1816,80 @@ class FakeQuota(object):
info=copy.deepcopy(quota_attrs),
loaded=True)
return quota
+
+
+class FakeFloatingIPPortForwarding(object):
+ """"Fake one or more Port forwarding"""
+
+ @staticmethod
+ def create_one_port_forwarding(attrs=None):
+ """Create a fake Port Forwarding.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with name, id, etc.
+ """
+ attrs = attrs or {}
+ floatingip_id = (
+ attrs.get('floatingip_id') or'floating-ip-id-' + uuid.uuid4().hex
+ )
+ # Set default attributes.
+ port_forwarding_attrs = {
+ 'id': uuid.uuid4().hex,
+ 'floatingip_id': floatingip_id,
+ 'internal_port_id': 'internal-port-id-' + uuid.uuid4().hex,
+ 'internal_ip_address': '192.168.1.2',
+ 'internal_port': randint(1, 65535),
+ 'external_port': randint(1, 65535),
+ 'protocol': 'tcp',
+ }
+
+ # Overwrite default attributes.
+ port_forwarding_attrs.update(attrs)
+
+ port_forwarding = fakes.FakeResource(
+ info=copy.deepcopy(port_forwarding_attrs),
+ loaded=True
+ )
+ return port_forwarding
+
+ @staticmethod
+ def create_port_forwardings(attrs=None, count=2):
+ """Create multiple fake Port Forwarding.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of Port Forwarding rule to fake
+ :return:
+ A list of FakeResource objects faking the Port Forwardings
+ """
+ port_forwardings = []
+ for i in range(0, count):
+ port_forwardings.append(
+ FakeFloatingIPPortForwarding.create_one_port_forwarding(attrs)
+ )
+ return port_forwardings
+
+ @staticmethod
+ def get_port_forwardings(port_forwardings=None, count=2):
+ """Get a list of faked Port Forwardings.
+
+ If port forwardings list is provided, then initialize the Mock object
+ with the list. Otherwise create one.
+
+ :param List port forwardings:
+ A list of FakeResource objects faking port forwardings
+ :param int count:
+ The number of Port Forwardings to fake
+ :return:
+ An iterable Mock object with side_effect set to a list of faked
+ Port Forwardings
+ """
+ if port_forwardings is None:
+ port_forwardings = (
+ FakeFloatingIPPortForwarding.create_port_forwardings(count)
+ )
+
+ return mock.Mock(side_effect=port_forwardings)
diff --git a/openstackclient/tests/unit/network/v2/test_address_scope.py b/openstackclient/tests/unit/network/v2/test_address_scope.py
index 40067188..17f13e83 100644
--- a/openstackclient/tests/unit/network/v2/test_address_scope.py
+++ b/openstackclient/tests/unit/network/v2/test_address_scope.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip_compute.py b/openstackclient/tests/unit/network/v2/test_floating_ip_compute.py
index df47e63e..18212cf7 100644
--- a/openstackclient/tests/unit/network/v2/test_floating_ip_compute.py
+++ b/openstackclient/tests/unit/network/v2/test_floating_ip_compute.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip_network.py b/openstackclient/tests/unit/network/v2/test_floating_ip_network.py
index cbd4da38..dbcd5c97 100644
--- a/openstackclient/tests/unit/network/v2/test_floating_ip_network.py
+++ b/openstackclient/tests/unit/network/v2/test_floating_ip_network.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
@@ -776,6 +776,32 @@ class TestSetFloatingIP(TestFloatingIPNetwork):
self.network.update_ip.assert_called_once_with(
self.floating_ip, **attrs)
+ def test_description_option(self):
+ arglist = [
+ self.floating_ip.id,
+ '--port', self.floating_ip.port_id,
+ '--description', self.floating_ip.description,
+ ]
+ verifylist = [
+ ('floating_ip', self.floating_ip.id),
+ ('port', self.floating_ip.port_id),
+ ('description', self.floating_ip.description),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'port_id': self.floating_ip.port_id,
+ 'description': self.floating_ip.description,
+ }
+ self.network.find_ip.assert_called_once_with(
+ self.floating_ip.id,
+ ignore_missing=False,
+ )
+ self.network.update_ip.assert_called_once_with(
+ self.floating_ip, **attrs)
+
def test_qos_policy_option(self):
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py b/openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py
index 591f58ca..3dd99362 100644
--- a/openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py
+++ b/openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py
@@ -11,7 +11,7 @@
# under the License.
#
-import mock
+from unittest import mock
from openstackclient.network.v2 import floating_ip_pool
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip_port_forwarding.py b/openstackclient/tests/unit/network/v2/test_floating_ip_port_forwarding.py
new file mode 100644
index 00000000..ea6cdd26
--- /dev/null
+++ b/openstackclient/tests/unit/network/v2/test_floating_ip_port_forwarding.py
@@ -0,0 +1,502 @@
+# Copyright (c) 2018 China Telecom Corporation
+# 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 unittest.mock import call
+
+from osc_lib import exceptions
+
+from openstackclient.network.v2 import floating_ip_port_forwarding
+from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes_v2
+from openstackclient.tests.unit.network.v2 import fakes as network_fakes
+from openstackclient.tests.unit import utils as tests_utils
+
+
+class TestFloatingIPPortForwarding(network_fakes.TestNetworkV2):
+
+ def setUp(self):
+ super(TestFloatingIPPortForwarding, self).setUp()
+ self.network = self.app.client_manager.network
+ self.floating_ip = (network_fakes.FakeFloatingIP.
+ create_one_floating_ip())
+ self.port = network_fakes.FakePort.create_one_port()
+ self.project = identity_fakes_v2.FakeProject.create_one_project()
+ self.network.find_port = mock.Mock(return_value=self.port)
+
+
+class TestCreateFloatingIPPortForwarding(TestFloatingIPPortForwarding):
+
+ def setUp(self):
+ project_id = ''
+ super(TestCreateFloatingIPPortForwarding, self).setUp()
+ self.new_port_forwarding = (
+ network_fakes.FakeFloatingIPPortForwarding.
+ create_one_port_forwarding(
+ attrs={
+ 'internal_port_id': self.port.id,
+ 'floatingip_id': self.floating_ip.id,
+ }
+ )
+ )
+ self.network.create_floating_ip_port_forwarding = mock.Mock(
+ return_value=self.new_port_forwarding)
+
+ self.network.find_ip = mock.Mock(
+ return_value=self.floating_ip
+ )
+
+ # Get the command object to test
+ self.cmd = floating_ip_port_forwarding.CreateFloatingIPPortForwarding(
+ self.app, self.namespace)
+
+ self.columns = (
+ 'external_port',
+ 'floatingip_id',
+ 'id',
+ 'internal_ip_address',
+ 'internal_port',
+ 'internal_port_id',
+ 'project_id',
+ 'protocol'
+ )
+
+ self.data = (
+ self.new_port_forwarding.external_port,
+ self.new_port_forwarding.floatingip_id,
+ self.new_port_forwarding.id,
+ self.new_port_forwarding.internal_ip_address,
+ self.new_port_forwarding.internal_port,
+ self.new_port_forwarding.internal_port_id,
+ project_id,
+ self.new_port_forwarding.protocol,
+ )
+
+ def test_create_no_options(self):
+ arglist = []
+ verifylist = []
+
+ # Missing required args should bail here
+ self.assertRaises(tests_utils.ParserException, self.check_parser,
+ self.cmd, arglist, verifylist)
+
+ def test_create_all_options(self):
+ arglist = [
+ '--port', self.new_port_forwarding.internal_port_id,
+ '--internal-protocol-port',
+ str(self.new_port_forwarding.internal_port),
+ '--external-protocol-port',
+ str(self.new_port_forwarding.external_port),
+ '--protocol', self.new_port_forwarding.protocol,
+ self.new_port_forwarding.floatingip_id,
+ '--internal-ip-address',
+ self.new_port_forwarding.internal_ip_address,
+ ]
+ verifylist = [
+ ('port', self.new_port_forwarding.internal_port_id),
+ ('internal_protocol_port', self.new_port_forwarding.internal_port),
+ ('external_protocol_port', self.new_port_forwarding.external_port),
+ ('protocol', self.new_port_forwarding.protocol),
+ ('floating_ip', self.new_port_forwarding.floatingip_id),
+ ('internal_ip_address', self.new_port_forwarding.
+ internal_ip_address),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.create_floating_ip_port_forwarding.\
+ assert_called_once_with(
+ self.new_port_forwarding.floatingip_id,
+ **{
+ 'external_port': self.new_port_forwarding.external_port,
+ 'internal_ip_address': self.new_port_forwarding.
+ internal_ip_address,
+ 'internal_port': self.new_port_forwarding.internal_port,
+ 'internal_port_id': self.new_port_forwarding.
+ internal_port_id,
+ 'protocol': self.new_port_forwarding.protocol,
+ })
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+
+class TestDeleteFloatingIPPortForwarding(TestFloatingIPPortForwarding):
+
+ def setUp(self):
+ super(TestDeleteFloatingIPPortForwarding, self).setUp()
+ self._port_forwarding = (
+ network_fakes.FakeFloatingIPPortForwarding.create_port_forwardings(
+ count=2, attrs={
+ 'floatingip_id': self.floating_ip.id,
+ }
+ )
+ )
+ self.network.delete_floating_ip_port_forwarding = mock.Mock(
+ return_value=None
+ )
+
+ self.network.find_ip = mock.Mock(
+ return_value=self.floating_ip
+ )
+ # Get the command object to test
+ self.cmd = floating_ip_port_forwarding.DeleteFloatingIPPortForwarding(
+ self.app, self.namespace)
+
+ def test_port_forwarding_delete(self):
+ arglist = [
+ self.floating_ip.id,
+ self._port_forwarding[0].id,
+ ]
+ verifylist = [
+ ('floating_ip', self.floating_ip.id),
+ ('port_forwarding_id', [self._port_forwarding[0].id]),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.network.delete_floating_ip_port_forwarding.\
+ assert_called_once_with(
+ self.floating_ip.id,
+ self._port_forwarding[0].id,
+ ignore_missing=False
+ )
+
+ self.assertIsNone(result)
+
+ def test_multi_port_forwardings_delete(self):
+ arglist = []
+ pf_id = []
+
+ arglist.append(str(self.floating_ip))
+
+ for a in self._port_forwarding:
+ arglist.append(a.id)
+ pf_id.append(a.id)
+
+ verifylist = [
+ ('floating_ip', str(self.floating_ip)),
+ ('port_forwarding_id', pf_id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ calls = []
+ for a in self._port_forwarding:
+ calls.append(call(a.floatingip_id, a.id, ignore_missing=False))
+
+ self.network.delete_floating_ip_port_forwarding.assert_has_calls(calls)
+ self.assertIsNone(result)
+
+ def test_multi_port_forwarding_delete_with_exception(self):
+ arglist = [
+ self.floating_ip.id,
+ self._port_forwarding[0].id,
+ 'unexist_port_forwarding_id',
+ ]
+ verifylist = [
+ ('floating_ip', self.floating_ip.id),
+ ('port_forwarding_id',
+ [self._port_forwarding[0].id, 'unexist_port_forwarding_id']),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ delete_mock_result = [None, exceptions.CommandError]
+
+ self.network.delete_floating_ip_port_forwarding = (
+ mock.MagicMock(side_effect=delete_mock_result)
+ )
+
+ try:
+ self.cmd.take_action(parsed_args)
+ self.fail('CommandError should be raised.')
+ except exceptions.CommandError as e:
+ self.assertEqual(
+ '1 of 2 Port forwarding failed to delete.',
+ str(e)
+ )
+
+ self.network.delete_floating_ip_port_forwarding.\
+ assert_any_call(
+ self.floating_ip.id,
+ 'unexist_port_forwarding_id',
+ ignore_missing=False
+ )
+ self.network.delete_floating_ip_port_forwarding.\
+ assert_any_call(
+ self.floating_ip.id,
+ self._port_forwarding[0].id,
+ ignore_missing=False
+ )
+
+
+class TestListFloatingIPPortForwarding(TestFloatingIPPortForwarding):
+
+ columns = (
+ 'ID',
+ 'Internal Port ID',
+ 'Internal IP Address',
+ 'Internal Port',
+ 'External Port',
+ 'Protocol'
+ )
+
+ def setUp(self):
+ super(TestListFloatingIPPortForwarding, self).setUp()
+ self.port_forwardings = (
+ network_fakes.FakeFloatingIPPortForwarding.create_port_forwardings(
+ count=3, attrs={
+ 'internal_port_id': self.port.id,
+ 'floatingip_id': self.floating_ip.id,
+ }
+ )
+ )
+ self.data = []
+ for port_forwarding in self.port_forwardings:
+ self.data.append((
+ port_forwarding.id,
+ port_forwarding.internal_port_id,
+ port_forwarding.internal_ip_address,
+ port_forwarding.internal_port,
+ port_forwarding.external_port,
+ port_forwarding.protocol,
+ ))
+ self.network.floating_ip_port_forwardings = mock.Mock(
+ return_value=self.port_forwardings
+ )
+ self.network.find_ip = mock.Mock(
+ return_value=self.floating_ip
+ )
+ # Get the command object to test
+ self.cmd = floating_ip_port_forwarding.ListFloatingIPPortForwarding(
+ self.app,
+ self.namespace
+ )
+
+ def test_port_forwarding_list(self):
+ arglist = [
+ self.floating_ip.id
+ ]
+ verifylist = [
+ ('floating_ip', self.floating_ip.id)
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.floating_ip_port_forwardings.assert_called_once_with(
+ self.floating_ip,
+ **{}
+ )
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
+ def test_port_forwarding_list_all_options(self):
+ arglist = [
+ '--port', self.port_forwardings[0].internal_port_id,
+ '--external-protocol-port',
+ str(self.port_forwardings[0].external_port),
+ '--protocol', self.port_forwardings[0].protocol,
+ self.port_forwardings[0].floatingip_id,
+ ]
+
+ verifylist = [
+ ('port', self.port_forwardings[0].internal_port_id),
+ ('external_protocol_port',
+ str(self.port_forwardings[0].external_port)),
+ ('protocol', self.port_forwardings[0].protocol),
+ ('floating_ip', self.port_forwardings[0].floatingip_id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ query = {
+ 'internal_port_id': self.port_forwardings[0].internal_port_id,
+ 'external_port': str(self.port_forwardings[0].external_port),
+ 'protocol': self.port_forwardings[0].protocol,
+ }
+
+ self.network.floating_ip_port_forwardings.assert_called_once_with(
+ self.floating_ip,
+ **query
+ )
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
+
+class TestSetFloatingIPPortForwarding(TestFloatingIPPortForwarding):
+
+ # The Port Forwarding to set.
+ def setUp(self):
+ super(TestSetFloatingIPPortForwarding, self).setUp()
+ self._port_forwarding = (
+ network_fakes.FakeFloatingIPPortForwarding.
+ create_one_port_forwarding(
+ attrs={
+ 'floatingip_id': self.floating_ip.id,
+ }
+ )
+ )
+ self.network.update_floating_ip_port_forwarding = mock.Mock(
+ return_value=None
+ )
+
+ self.network.find_floating_ip_port_forwarding = mock.Mock(
+ return_value=self._port_forwarding)
+ self.network.find_ip = mock.Mock(
+ return_value=self.floating_ip
+ )
+ # Get the command object to test
+ self.cmd = floating_ip_port_forwarding.SetFloatingIPPortForwarding(
+ self.app,
+ self.namespace
+ )
+
+ def test_set_nothing(self):
+ arglist = [
+ self._port_forwarding.floatingip_id,
+ self._port_forwarding.id,
+ ]
+ verifylist = [
+ ('floating_ip', self._port_forwarding.floatingip_id),
+ ('port_forwarding_id', self._port_forwarding.id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+
+ attrs = {}
+ self.network.update_floating_ip_port_forwarding.assert_called_with(
+ self._port_forwarding.floatingip_id,
+ self._port_forwarding.id,
+ **attrs
+ )
+ self.assertIsNone(result)
+
+ def test_set_all_thing(self):
+ arglist = [
+ '--port', self.port.id,
+ '--internal-ip-address', 'new_internal_ip_address',
+ '--internal-protocol-port', '100',
+ '--external-protocol-port', '200',
+ '--protocol', 'tcp',
+ self._port_forwarding.floatingip_id,
+ self._port_forwarding.id,
+ ]
+ verifylist = [
+ ('port', self.port.id),
+ ('internal_ip_address', 'new_internal_ip_address'),
+ ('internal_protocol_port', 100),
+ ('external_protocol_port', 200),
+ ('protocol', 'tcp'),
+ ('floating_ip', self._port_forwarding.floatingip_id),
+ ('port_forwarding_id', self._port_forwarding.id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+ attrs = {
+ 'internal_port_id': self.port.id,
+ 'internal_ip_address': 'new_internal_ip_address',
+ 'internal_port': 100,
+ 'external_port': 200,
+ 'protocol': 'tcp',
+ }
+ self.network.update_floating_ip_port_forwarding.assert_called_with(
+ self._port_forwarding.floatingip_id,
+ self._port_forwarding.id,
+ **attrs
+ )
+ self.assertIsNone(result)
+
+
+class TestShowFloatingIPPortForwarding(TestFloatingIPPortForwarding):
+
+ # The port forwarding to show.
+ columns = (
+ 'external_port',
+ 'floatingip_id',
+ 'id',
+ 'internal_ip_address',
+ 'internal_port',
+ 'internal_port_id',
+ 'project_id',
+ 'protocol',
+ )
+
+ def setUp(self):
+ project_id = ''
+ super(TestShowFloatingIPPortForwarding, self).setUp()
+ self._port_forwarding = (
+ network_fakes.FakeFloatingIPPortForwarding.
+ create_one_port_forwarding(
+ attrs={
+ 'floatingip_id': self.floating_ip.id,
+ }
+ )
+ )
+ self.data = (
+ self._port_forwarding.external_port,
+ self._port_forwarding.floatingip_id,
+ self._port_forwarding.id,
+ self._port_forwarding.internal_ip_address,
+ self._port_forwarding.internal_port,
+ self._port_forwarding.internal_port_id,
+ project_id,
+ self._port_forwarding.protocol,
+ )
+ self.network.find_floating_ip_port_forwarding = mock.Mock(
+ return_value=self._port_forwarding
+ )
+ self.network.find_ip = mock.Mock(
+ return_value=self.floating_ip
+ )
+ # Get the command object to test
+ self.cmd = floating_ip_port_forwarding.ShowFloatingIPPortForwarding(
+ self.app,
+ self.namespace
+ )
+
+ def test_show_no_options(self):
+ arglist = []
+ verifylist = []
+
+ # Missing required args should bail here
+ self.assertRaises(tests_utils.ParserException, self.check_parser,
+ self.cmd, arglist, verifylist)
+
+ def test_show_default_options(self):
+ arglist = [
+ self._port_forwarding.floatingip_id,
+ self._port_forwarding.id,
+ ]
+ verifylist = [
+ ('floating_ip', self._port_forwarding.floatingip_id),
+ ('port_forwarding_id', self._port_forwarding.id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.find_floating_ip_port_forwarding.assert_called_once_with(
+ self.floating_ip,
+ self._port_forwarding.id,
+ ignore_missing=False
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(list(self.data), list(data))
diff --git a/openstackclient/tests/unit/network/v2/test_ip_availability.py b/openstackclient/tests/unit/network/v2/test_ip_availability.py
index 21508a8d..9a712704 100644
--- a/openstackclient/tests/unit/network/v2/test_ip_availability.py
+++ b/openstackclient/tests/unit/network/v2/test_ip_availability.py
@@ -11,7 +11,7 @@
# under the License.
#
-import mock
+from unittest import mock
from osc_lib.cli import format_columns
diff --git a/openstackclient/tests/unit/network/v2/test_network.py b/openstackclient/tests/unit/network/v2/test_network.py
index 5c97c363..45d6008b 100644
--- a/openstackclient/tests/unit/network/v2/test_network.py
+++ b/openstackclient/tests/unit/network/v2/test_network.py
@@ -12,9 +12,8 @@
#
import random
-
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
@@ -279,6 +278,24 @@ class TestCreateNetworkIdentityV3(TestNetwork):
def test_create_with_no_tag(self):
self._test_create_with_tag(add_tags=False)
+ def test_create_default_internal(self):
+ arglist = [
+ self._network.name,
+ "--default",
+ ]
+ verifylist = [
+ ('name', self._network.name),
+ ('enable', True),
+ ('share', None),
+ ('project', None),
+ ('external', False),
+ ('default', True),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
class TestCreateNetworkIdentityV2(TestNetwork):
@@ -1026,6 +1043,21 @@ class TestSetNetwork(TestNetwork):
def test_set_with_no_tag(self):
self._test_set_tags(with_tags=False)
+ def test_set_default_internal(self):
+ arglist = [
+ self._network.name,
+ '--internal',
+ '--default',
+ ]
+ verifylist = [
+ ('internal', True),
+ ('default', True),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
class TestShowNetwork(TestNetwork):
diff --git a/openstackclient/tests/unit/network/v2/test_network_agent.py b/openstackclient/tests/unit/network/v2/test_network_agent.py
index 8500d08e..3181ee78 100644
--- a/openstackclient/tests/unit/network/v2/test_network_agent.py
+++ b/openstackclient/tests/unit/network/v2/test_network_agent.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py b/openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py
index 1a231160..e9687a70 100644
--- a/openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py
+++ b/openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py
@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
+from unittest import mock
from openstackclient.network.v2 import network_auto_allocated_topology
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
diff --git a/openstackclient/tests/unit/network/v2/test_network_compute.py b/openstackclient/tests/unit/network/v2/test_network_compute.py
index c649401c..89330fff 100644
--- a/openstackclient/tests/unit/network/v2/test_network_compute.py
+++ b/openstackclient/tests/unit/network/v2/test_network_compute.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_flavor.py b/openstackclient/tests/unit/network/v2/test_network_flavor.py
index 896a1725..010f53d3 100644
--- a/openstackclient/tests/unit/network/v2/test_network_flavor.py
+++ b/openstackclient/tests/unit/network/v2/test_network_flavor.py
@@ -14,7 +14,7 @@
# under the License.
#
-import mock
+from unittest import mock
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_flavor_profile.py b/openstackclient/tests/unit/network/v2/test_network_flavor_profile.py
index 91683241..fcf24da9 100644
--- a/openstackclient/tests/unit/network/v2/test_network_flavor_profile.py
+++ b/openstackclient/tests/unit/network/v2/test_network_flavor_profile.py
@@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
+from unittest import mock
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_meter.py b/openstackclient/tests/unit/network/v2/test_network_meter.py
index 2b96f7a6..4fadcfe1 100644
--- a/openstackclient/tests/unit/network/v2/test_network_meter.py
+++ b/openstackclient/tests/unit/network/v2/test_network_meter.py
@@ -13,8 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_meter_rule.py b/openstackclient/tests/unit/network/v2/test_network_meter_rule.py
index af481793..8f8922c0 100644
--- a/openstackclient/tests/unit/network/v2/test_network_meter_rule.py
+++ b/openstackclient/tests/unit/network/v2/test_network_meter_rule.py
@@ -13,8 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_qos_policy.py b/openstackclient/tests/unit/network/v2/test_network_qos_policy.py
index e7239932..d6a78410 100644
--- a/openstackclient/tests/unit/network/v2/test_network_qos_policy.py
+++ b/openstackclient/tests/unit/network/v2/test_network_qos_policy.py
@@ -13,8 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_qos_rule.py b/openstackclient/tests/unit/network/v2/test_network_qos_rule.py
index 5b54d318..217e481e 100644
--- a/openstackclient/tests/unit/network/v2/test_network_qos_rule.py
+++ b/openstackclient/tests/unit/network/v2/test_network_qos_rule.py
@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
+from unittest import mock
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py b/openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py
index 80c52bf7..08a83fab 100644
--- a/openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py
+++ b/openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py
@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
+from unittest import mock
from openstackclient.network.v2 import network_qos_rule_type as _qos_rule_type
from openstackclient.tests.unit.network.v2 import fakes as network_fakes
diff --git a/openstackclient/tests/unit/network/v2/test_network_rbac.py b/openstackclient/tests/unit/network/v2/test_network_rbac.py
index 96440091..078188ce 100644
--- a/openstackclient/tests/unit/network/v2/test_network_rbac.py
+++ b/openstackclient/tests/unit/network/v2/test_network_rbac.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_segment.py b/openstackclient/tests/unit/network/v2/test_network_segment.py
index 0639766d..6cd948e3 100644
--- a/openstackclient/tests/unit/network/v2/test_network_segment.py
+++ b/openstackclient/tests/unit/network/v2/test_network_segment.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_network_segment_range.py b/openstackclient/tests/unit/network/v2/test_network_segment_range.py
index 22e25df1..b60f1710 100644
--- a/openstackclient/tests/unit/network/v2/test_network_segment_range.py
+++ b/openstackclient/tests/unit/network/v2/test_network_segment_range.py
@@ -14,8 +14,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
@@ -24,6 +24,20 @@ from openstackclient.tests.unit.network.v2 import fakes as network_fakes
from openstackclient.tests.unit import utils as tests_utils
+class TestAuxiliaryFunctions(tests_utils.TestCase):
+
+ def test__get_ranges(self):
+ input_reference = [
+ ([1, 2, 3, 4, 5, 6, 7], ['1-7']),
+ ([1, 2, 5, 4, 3, 6, 7], ['1-7']),
+ ([1, 2, 4, 3, 7, 6], ['1-4', '6-7']),
+ ([1, 2, 4, 3, '13', 12, '7', '6'], ['1-4', '6-7', '12-13'])
+ ]
+ for input, reference in input_reference:
+ self.assertEqual(reference,
+ list(network_segment_range._get_ranges(input)))
+
+
class TestNetworkSegmentRange(network_fakes.TestNetworkV2):
def setUp(self):
diff --git a/openstackclient/tests/unit/network/v2/test_network_service_provider.py b/openstackclient/tests/unit/network/v2/test_network_service_provider.py
index 5ba85ddb..5e4ddea6 100644
--- a/openstackclient/tests/unit/network/v2/test_network_service_provider.py
+++ b/openstackclient/tests/unit/network/v2/test_network_service_provider.py
@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
+from unittest import mock
from openstackclient.network.v2 import network_service_provider \
as service_provider
diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py
index c30d682f..b1a18da6 100644
--- a/openstackclient/tests/unit/network/v2/test_port.py
+++ b/openstackclient/tests/unit/network/v2/test_port.py
@@ -12,9 +12,9 @@
#
import argparse
+from unittest import mock
+from unittest.mock import call
-import mock
-from mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils
@@ -61,6 +61,7 @@ class TestPort(network_fakes.TestNetworkV2):
'network_id',
'port_security_enabled',
'project_id',
+ 'qos_network_policy_id',
'qos_policy_id',
'security_group_ids',
'status',
@@ -91,6 +92,7 @@ class TestPort(network_fakes.TestNetworkV2):
fake_port.network_id,
fake_port.port_security_enabled,
fake_port.project_id,
+ fake_port.qos_network_policy_id,
fake_port.qos_policy_id,
format_columns.ListColumn(fake_port.security_group_ids),
fake_port.status,
diff --git a/openstackclient/tests/unit/network/v2/test_router.py b/openstackclient/tests/unit/network/v2/test_router.py
index 079b9746..38861b0a 100644
--- a/openstackclient/tests/unit/network/v2/test_router.py
+++ b/openstackclient/tests/unit/network/v2/test_router.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
@@ -1285,6 +1285,24 @@ class TestShowRouter(TestRouter):
self.assertNotIn("is_distributed", columns)
self.assertNotIn("is_ha", columns)
+ def test_show_no_extra_route_extension(self):
+ _router = network_fakes.FakeRouter.create_one_router({'routes': None})
+
+ arglist = [
+ _router.name,
+ ]
+ verifylist = [
+ ('router', _router.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(
+ self.network, "find_router", return_value=_router):
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.assertIn("routes", columns)
+ self.assertIsNone(list(data)[columns.index('routes')].human_readable())
+
class TestUnsetRouter(TestRouter):
diff --git a/openstackclient/tests/unit/network/v2/test_security_group_compute.py b/openstackclient/tests/unit/network/v2/test_security_group_compute.py
index df360068..b4ddcf80 100644
--- a/openstackclient/tests/unit/network/v2/test_security_group_compute.py
+++ b/openstackclient/tests/unit/network/v2/test_security_group_compute.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_security_group_network.py b/openstackclient/tests/unit/network/v2/test_security_group_network.py
index 57698ec5..67908fa8 100644
--- a/openstackclient/tests/unit/network/v2/test_security_group_network.py
+++ b/openstackclient/tests/unit/network/v2/test_security_group_network.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
@@ -285,7 +285,8 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
columns, data = self.cmd.take_action(parsed_args)
- self.network.security_groups.assert_called_once_with()
+ self.network.security_groups.assert_called_once_with(
+ fields=security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE)
self.assertEqual(self.columns, columns)
self.assertListItemEqual(self.data, list(data))
@@ -300,7 +301,8 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
columns, data = self.cmd.take_action(parsed_args)
- self.network.security_groups.assert_called_once_with()
+ self.network.security_groups.assert_called_once_with(
+ fields=security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE)
self.assertEqual(self.columns, columns)
self.assertListItemEqual(self.data, list(data))
@@ -316,7 +318,9 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
- filters = {'tenant_id': project.id, 'project_id': project.id}
+ filters = {
+ 'tenant_id': project.id, 'project_id': project.id,
+ 'fields': security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE}
self.network.security_groups.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
@@ -336,7 +340,9 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
- filters = {'tenant_id': project.id, 'project_id': project.id}
+ filters = {
+ 'tenant_id': project.id, 'project_id': project.id,
+ 'fields': security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE}
self.network.security_groups.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
@@ -362,7 +368,8 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
**{'tags': 'red,blue',
'any_tags': 'red,green',
'not_tags': 'orange,yellow',
- 'not_any_tags': 'black,white'}
+ 'not_any_tags': 'black,white',
+ 'fields': security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE}
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py b/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py
index cf5261b2..5720e305 100644
--- a/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py
+++ b/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py b/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py
index 49c3d5db..0a9522b0 100644
--- a/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py
+++ b/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_subnet.py b/openstackclient/tests/unit/network/v2/test_subnet.py
index d34be18c..47d0c6b4 100644
--- a/openstackclient/tests/unit/network/v2/test_subnet.py
+++ b/openstackclient/tests/unit/network/v2/test_subnet.py
@@ -11,8 +11,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/network/v2/test_subnet_pool.py b/openstackclient/tests/unit/network/v2/test_subnet_pool.py
index 2271c089..eb454646 100644
--- a/openstackclient/tests/unit/network/v2/test_subnet_pool.py
+++ b/openstackclient/tests/unit/network/v2/test_subnet_pool.py
@@ -12,9 +12,8 @@
#
import argparse
-
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/object/v1/fakes.py b/openstackclient/tests/unit/object/v1/fakes.py
index 5d65d106..0ed791a5 100644
--- a/openstackclient/tests/unit/object/v1/fakes.py
+++ b/openstackclient/tests/unit/object/v1/fakes.py
@@ -13,9 +13,8 @@
# under the License.
#
-import six
-
from keystoneauth1 import session
+import six
from openstackclient.api import object_store_v1 as object_store
from openstackclient.tests.unit import utils
diff --git a/openstackclient/tests/unit/object/v1/test_container.py b/openstackclient/tests/unit/object/v1/test_container.py
index 39e2d80f..7d3cc8d8 100644
--- a/openstackclient/tests/unit/object/v1/test_container.py
+++ b/openstackclient/tests/unit/object/v1/test_container.py
@@ -14,8 +14,7 @@
#
import copy
-
-import mock
+from unittest import mock
from openstackclient.api import object_store_v1 as object_store
from openstackclient.object.v1 import container
diff --git a/openstackclient/tests/unit/object/v1/test_container_all.py b/openstackclient/tests/unit/object/v1/test_container_all.py
index 58c90e36..654cfbc7 100644
--- a/openstackclient/tests/unit/object/v1/test_container_all.py
+++ b/openstackclient/tests/unit/object/v1/test_container_all.py
@@ -70,6 +70,75 @@ class TestContainerCreate(TestContainerAll):
)]
self.assertEqual(datalist, list(data))
+ def test_object_create_container_storage_policy(self):
+ self.requests_mock.register_uri(
+ 'PUT',
+ object_fakes.ENDPOINT + '/ernie',
+ headers={
+ 'x-trans-id': '314159',
+ 'x-storage-policy': 'o1--sr-r3'
+ },
+ status_code=200,
+ )
+
+ arglist = [
+ 'ernie',
+ '--storage-policy',
+ 'o1--sr-r3'
+ ]
+ verifylist = [
+ ('containers', ['ernie']),
+ ('storage_policy', 'o1--sr-r3')
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.assertEqual(self.columns, columns)
+ datalist = [(
+ object_fakes.ACCOUNT_ID,
+ 'ernie',
+ '314159',
+ )]
+ self.assertEqual(datalist, list(data))
+
+ def test_object_create_container_public(self):
+ self.requests_mock.register_uri(
+ 'PUT',
+ object_fakes.ENDPOINT + '/ernie',
+ headers={
+ 'x-trans-id': '314159',
+ 'x-container-read': '.r:*,.rlistings'
+ },
+ status_code=200,
+ )
+
+ arglist = [
+ 'ernie',
+ '--public'
+ ]
+ verifylist = [
+ ('containers', ['ernie']),
+ ('public', True)
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.assertEqual(self.columns, columns)
+ datalist = [(
+ object_fakes.ACCOUNT_ID,
+ 'ernie',
+ '314159',
+ )]
+ self.assertEqual(datalist, list(data))
+
def test_object_create_container_more(self):
self.requests_mock.register_uri(
'PUT',
@@ -300,6 +369,7 @@ class TestContainerShow(TestContainerAll):
'x-container-write': 'wsx',
'x-container-sync-to': 'edc',
'x-container-sync-key': 'rfv',
+ 'x-storage-policy': 'o1--sr-r3'
}
self.requests_mock.register_uri(
'HEAD',
@@ -327,6 +397,7 @@ class TestContainerShow(TestContainerAll):
'container',
'object_count',
'read_acl',
+ 'storage_policy',
'sync_key',
'sync_to',
'write_acl',
@@ -338,6 +409,7 @@ class TestContainerShow(TestContainerAll):
'ernie',
'42',
'qaz',
+ 'o1--sr-r3',
'rfv',
'edc',
'wsx',
diff --git a/openstackclient/tests/unit/object/v1/test_object.py b/openstackclient/tests/unit/object/v1/test_object.py
index b6299373..fc3073c8 100644
--- a/openstackclient/tests/unit/object/v1/test_object.py
+++ b/openstackclient/tests/unit/object/v1/test_object.py
@@ -14,8 +14,7 @@
#
import copy
-
-import mock
+from unittest import mock
from openstackclient.api import object_store_v1 as object_store
from openstackclient.object.v1 import object as obj
diff --git a/openstackclient/tests/unit/object/v1/test_object_all.py b/openstackclient/tests/unit/object/v1/test_object_all.py
index 08a7534d..dd587142 100644
--- a/openstackclient/tests/unit/object/v1/test_object_all.py
+++ b/openstackclient/tests/unit/object/v1/test_object_all.py
@@ -12,8 +12,8 @@
#
import copy
+from unittest import mock
-import mock
from osc_lib import exceptions
from requests_mock.contrib import fixture
import six
diff --git a/openstackclient/tests/unit/test_shell.py b/openstackclient/tests/unit/test_shell.py
index 31675c47..94f4f44d 100644
--- a/openstackclient/tests/unit/test_shell.py
+++ b/openstackclient/tests/unit/test_shell.py
@@ -15,8 +15,8 @@
import os
import sys
+from unittest import mock
-import mock
from osc_lib.tests import utils as osc_lib_test_utils
from oslo_utils import importutils
import wrapt
diff --git a/openstackclient/tests/unit/utils.py b/openstackclient/tests/unit/utils.py
index c15d8bbf..4f1bc46a 100644
--- a/openstackclient/tests/unit/utils.py
+++ b/openstackclient/tests/unit/utils.py
@@ -16,11 +16,11 @@
import os
+from cliff import columns as cliff_columns
import fixtures
+from six.moves import StringIO
import testtools
-from cliff import columns as cliff_columns
-
from openstackclient.tests.unit import fakes
@@ -72,10 +72,13 @@ class TestCommand(TestCase):
def check_parser(self, cmd, args, verify_args):
cmd_parser = cmd.get_parser('check_parser')
- try:
- parsed_args = cmd_parser.parse_args(args)
- except SystemExit:
- raise ParserException("Argument parse failed")
+ stderr = StringIO()
+ with fixtures.MonkeyPatch('sys.stderr', stderr):
+ try:
+ parsed_args = cmd_parser.parse_args(args)
+ except SystemExit:
+ raise ParserException("Argument parse failed: %s" %
+ stderr.getvalue())
for av in verify_args:
attr, value = av
if attr:
diff --git a/openstackclient/tests/unit/volume/test_find_resource.py b/openstackclient/tests/unit/volume/test_find_resource.py
index 60591eff..208f55b9 100644
--- a/openstackclient/tests/unit/volume/test_find_resource.py
+++ b/openstackclient/tests/unit/volume/test_find_resource.py
@@ -13,7 +13,7 @@
# under the License.
#
-import mock
+from unittest import mock
from cinderclient.v3 import volume_snapshots
from cinderclient.v3 import volumes
diff --git a/openstackclient/tests/unit/volume/v1/fakes.py b/openstackclient/tests/unit/volume/v1/fakes.py
index de9c724f..adb775ed 100644
--- a/openstackclient/tests/unit/volume/v1/fakes.py
+++ b/openstackclient/tests/unit/volume/v1/fakes.py
@@ -15,10 +15,9 @@
import copy
import random
+from unittest import mock
import uuid
-import mock
-
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.unit import utils
diff --git a/openstackclient/tests/unit/volume/v1/test_qos_specs.py b/openstackclient/tests/unit/volume/v1/test_qos_specs.py
index 11dc8084..83c533b6 100644
--- a/openstackclient/tests/unit/volume/v1/test_qos_specs.py
+++ b/openstackclient/tests/unit/volume/v1/test_qos_specs.py
@@ -14,9 +14,8 @@
#
import copy
-
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/volume/v1/test_transfer_request.py b/openstackclient/tests/unit/volume/v1/test_transfer_request.py
index 680561d5..333bf526 100644
--- a/openstackclient/tests/unit/volume/v1/test_transfer_request.py
+++ b/openstackclient/tests/unit/volume/v1/test_transfer_request.py
@@ -12,8 +12,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
from osc_lib import utils
diff --git a/openstackclient/tests/unit/volume/v1/test_type.py b/openstackclient/tests/unit/volume/v1/test_type.py
index beff8336..8bee5747 100644
--- a/openstackclient/tests/unit/volume/v1/test_type.py
+++ b/openstackclient/tests/unit/volume/v1/test_type.py
@@ -12,8 +12,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/volume/v1/test_volume.py b/openstackclient/tests/unit/volume/v1/test_volume.py
index c4154555..25cdf92a 100644
--- a/openstackclient/tests/unit/volume/v1/test_volume.py
+++ b/openstackclient/tests/unit/volume/v1/test_volume.py
@@ -14,9 +14,8 @@
#
import argparse
-
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/volume/v1/test_volume_backup.py b/openstackclient/tests/unit/volume/v1/test_volume_backup.py
index 20be6e46..20aadcd3 100644
--- a/openstackclient/tests/unit/volume/v1/test_volume_backup.py
+++ b/openstackclient/tests/unit/volume/v1/test_volume_backup.py
@@ -12,8 +12,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
from osc_lib import utils
diff --git a/openstackclient/tests/unit/volume/v2/fakes.py b/openstackclient/tests/unit/volume/v2/fakes.py
index 5f976b06..5f18990e 100644
--- a/openstackclient/tests/unit/volume/v2/fakes.py
+++ b/openstackclient/tests/unit/volume/v2/fakes.py
@@ -14,10 +14,9 @@
import copy
import random
+from unittest import mock
import uuid
-import mock
-
from osc_lib.cli import format_columns
from openstackclient.tests.unit import fakes
diff --git a/openstackclient/tests/unit/volume/v2/test_consistency_group.py b/openstackclient/tests/unit/volume/v2/test_consistency_group.py
index d2388182..c3bd71e3 100644
--- a/openstackclient/tests/unit/volume/v2/test_consistency_group.py
+++ b/openstackclient/tests/unit/volume/v2/test_consistency_group.py
@@ -12,8 +12,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py b/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py
index 3bfe93df..2202b85b 100644
--- a/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py
+++ b/openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py
@@ -12,7 +12,7 @@
# under the License.
#
-from mock import call
+from unittest.mock import call
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
from openstackclient.volume.v2 import consistency_group_snapshot
diff --git a/openstackclient/tests/unit/volume/v2/test_qos_specs.py b/openstackclient/tests/unit/volume/v2/test_qos_specs.py
index 454747f5..073ec570 100644
--- a/openstackclient/tests/unit/volume/v2/test_qos_specs.py
+++ b/openstackclient/tests/unit/volume/v2/test_qos_specs.py
@@ -14,9 +14,8 @@
#
import copy
-
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/volume/v2/test_transfer_request.py b/openstackclient/tests/unit/volume/v2/test_transfer_request.py
index 1ea6648f..c9dce3ca 100644
--- a/openstackclient/tests/unit/volume/v2/test_transfer_request.py
+++ b/openstackclient/tests/unit/volume/v2/test_transfer_request.py
@@ -12,8 +12,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
from osc_lib import utils
diff --git a/openstackclient/tests/unit/volume/v2/test_type.py b/openstackclient/tests/unit/volume/v2/test_type.py
index 17915928..f13d0851 100644
--- a/openstackclient/tests/unit/volume/v2/test_type.py
+++ b/openstackclient/tests/unit/volume/v2/test_type.py
@@ -12,8 +12,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py
index 332b50a7..5d41b3a1 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume.py
@@ -13,9 +13,8 @@
#
import argparse
-
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib.cli import format_columns
from osc_lib import exceptions
diff --git a/openstackclient/tests/unit/volume/v2/test_volume_backup.py b/openstackclient/tests/unit/volume/v2/test_volume_backup.py
index 30c7915d..4e1f7ee1 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume_backup.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume_backup.py
@@ -12,8 +12,8 @@
# under the License.
#
-import mock
-from mock import call
+from unittest import mock
+from unittest.mock import call
from osc_lib import exceptions
from osc_lib import utils