tests: Use SDK objects where expected
We had not migrated a number of tests to use SDK objects instead of fake novaclient-like objects when migrating the commands themselves. Address this now. Change-Id: Ib0da07fd9d793968b111986bd36a6d4311469d4e Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
19be070204
commit
31ae635ffe
@ -19,16 +19,19 @@ from unittest import mock
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from novaclient import api_versions
|
from novaclient import api_versions
|
||||||
|
from openstack.compute.v2 import aggregate as _aggregate
|
||||||
from openstack.compute.v2 import flavor as _flavor
|
from openstack.compute.v2 import flavor as _flavor
|
||||||
from openstack.compute.v2 import hypervisor as _hypervisor
|
from openstack.compute.v2 import hypervisor as _hypervisor
|
||||||
|
from openstack.compute.v2 import keypair as _keypair
|
||||||
from openstack.compute.v2 import migration as _migration
|
from openstack.compute.v2 import migration as _migration
|
||||||
from openstack.compute.v2 import server as _server
|
from openstack.compute.v2 import server as _server
|
||||||
from openstack.compute.v2 import server_action as _server_action
|
from openstack.compute.v2 import server_action as _server_action
|
||||||
from openstack.compute.v2 import server_group as _server_group
|
from openstack.compute.v2 import server_group as _server_group
|
||||||
from openstack.compute.v2 import server_interface as _server_interface
|
from openstack.compute.v2 import server_interface as _server_interface
|
||||||
from openstack.compute.v2 import server_migration as _server_migration
|
from openstack.compute.v2 import server_migration as _server_migration
|
||||||
from openstack.compute.v2 import service
|
from openstack.compute.v2 import service as _service
|
||||||
from openstack.compute.v2 import volume_attachment
|
from openstack.compute.v2 import usage as _usage
|
||||||
|
from openstack.compute.v2 import volume_attachment as _volume_attachment
|
||||||
|
|
||||||
from openstackclient.api import compute_v2
|
from openstackclient.api import compute_v2
|
||||||
from openstackclient.tests.unit import fakes
|
from openstackclient.tests.unit import fakes
|
||||||
@ -187,10 +190,8 @@ class TestComputev2(utils.TestCommand):
|
|||||||
def create_one_aggregate(attrs=None):
|
def create_one_aggregate(attrs=None):
|
||||||
"""Create a fake aggregate.
|
"""Create a fake aggregate.
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:return: A fake openstack.compute.v2.aggregate.Aggregate object
|
||||||
:return:
|
|
||||||
A FakeResource object, with id and other attributes
|
|
||||||
"""
|
"""
|
||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
|
|
||||||
@ -209,21 +210,16 @@ def create_one_aggregate(attrs=None):
|
|||||||
# Overwrite default attributes.
|
# Overwrite default attributes.
|
||||||
aggregate_info.update(attrs)
|
aggregate_info.update(attrs)
|
||||||
|
|
||||||
aggregate = fakes.FakeResource(
|
aggregate = _aggregate.Aggregate(**aggregate_info)
|
||||||
info=copy.deepcopy(aggregate_info), loaded=True
|
|
||||||
)
|
|
||||||
return aggregate
|
return aggregate
|
||||||
|
|
||||||
|
|
||||||
def create_aggregates(attrs=None, count=2):
|
def create_aggregates(attrs=None, count=2):
|
||||||
"""Create multiple fake aggregates.
|
"""Create multiple fake aggregates.
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:param int count: The number of aggregates to fake
|
||||||
:param int count:
|
:return: A list of fake openstack.compute.v2.aggregate.Aggregate objects
|
||||||
The number of aggregates to fake
|
|
||||||
:return:
|
|
||||||
A list of FakeResource objects faking the aggregates
|
|
||||||
"""
|
"""
|
||||||
aggregates = []
|
aggregates = []
|
||||||
for i in range(0, count):
|
for i in range(0, count):
|
||||||
@ -238,12 +234,9 @@ def get_aggregates(aggregates=None, count=2):
|
|||||||
If aggregates list is provided, then initialize the Mock object
|
If aggregates list is provided, then initialize the Mock object
|
||||||
with the list. Otherwise create one.
|
with the list. Otherwise create one.
|
||||||
|
|
||||||
:param List aggregates:
|
:return: A list of fake openstack.compute.v2.aggregate.Aggregate objects
|
||||||
A list of FakeResource objects faking aggregates
|
:param int count: The number of aggregates to fake
|
||||||
:param int count:
|
:return: An iterable Mock object with side_effect set to a list of faked
|
||||||
The number of aggregates to fake
|
|
||||||
:return:
|
|
||||||
An iterable Mock object with side_effect set to a list of faked
|
|
||||||
aggregates
|
aggregates
|
||||||
"""
|
"""
|
||||||
if aggregates is None:
|
if aggregates is None:
|
||||||
@ -491,19 +484,13 @@ def create_servers(attrs=None, methods=None, count=2):
|
|||||||
return servers
|
return servers
|
||||||
|
|
||||||
|
|
||||||
def create_one_sdk_server(attrs=None, methods=None):
|
def create_one_sdk_server(attrs=None):
|
||||||
"""Create a fake server for testing migration to sdk
|
"""Create a fake server for testing migration to sdk
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:return: A fake openstack.compute.v2.server.Server object,
|
||||||
:param dict methods:
|
|
||||||
A dictionary with all methods
|
|
||||||
:return:
|
|
||||||
A openstack.compute.v2.server.Server object,
|
|
||||||
with id, name, metadata, and so on
|
|
||||||
"""
|
"""
|
||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
methods = methods or {}
|
|
||||||
|
|
||||||
# Set default attributes.
|
# Set default attributes.
|
||||||
server_info = {
|
server_info = {
|
||||||
@ -529,22 +516,16 @@ def create_one_sdk_server(attrs=None, methods=None):
|
|||||||
return server
|
return server
|
||||||
|
|
||||||
|
|
||||||
def create_sdk_servers(attrs=None, methods=None, count=2):
|
def create_sdk_servers(attrs=None, count=2):
|
||||||
"""Create multiple fake servers for testing migration to sdk
|
"""Create multiple fake servers for testing migration to sdk
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:param int count: The number of servers to fake
|
||||||
:param dict methods:
|
:return: A list of fake openstack.compute.v2.server.Server objects
|
||||||
A dictionary with all methods
|
|
||||||
:param int count:
|
|
||||||
The number of servers to fake
|
|
||||||
:return:
|
|
||||||
A list of openstack.compute.v2.server.Server objects
|
|
||||||
faking the servers
|
|
||||||
"""
|
"""
|
||||||
servers = []
|
servers = []
|
||||||
for i in range(0, count):
|
for i in range(0, count):
|
||||||
servers.append(create_one_sdk_server(attrs, methods))
|
servers.append(create_one_sdk_server(attrs))
|
||||||
|
|
||||||
return servers
|
return servers
|
||||||
|
|
||||||
@ -555,12 +536,11 @@ def get_servers(servers=None, count=2):
|
|||||||
If servers list is provided, then initialize the Mock object with the
|
If servers list is provided, then initialize the Mock object with the
|
||||||
list. Otherwise create one.
|
list. Otherwise create one.
|
||||||
|
|
||||||
:param List servers:
|
:param list servers: A list of fake openstack.compute.v2.server.Server
|
||||||
A list of FakeResource objects faking servers
|
objects
|
||||||
:param int count:
|
:param int count:
|
||||||
The number of servers to fake
|
The number of servers to fake
|
||||||
:return:
|
:return: An iterable Mock object with side_effect set to a list of faked
|
||||||
An iterable Mock object with side_effect set to a list of faked
|
|
||||||
servers
|
servers
|
||||||
"""
|
"""
|
||||||
if servers is None:
|
if servers is None:
|
||||||
@ -614,10 +594,8 @@ def create_one_server_action(attrs=None):
|
|||||||
def create_one_service(attrs=None):
|
def create_one_service(attrs=None):
|
||||||
"""Create a fake service.
|
"""Create a fake service.
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:return: A fake openstack.compute.v2.service.Service object
|
||||||
:return:
|
|
||||||
A fake Service object, with id, host, binary, and so on
|
|
||||||
"""
|
"""
|
||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
|
|
||||||
@ -638,7 +616,7 @@ def create_one_service(attrs=None):
|
|||||||
# Overwrite default attributes.
|
# Overwrite default attributes.
|
||||||
service_info.update(attrs)
|
service_info.update(attrs)
|
||||||
|
|
||||||
return service.Service(**service_info)
|
return _service.Service(**service_info)
|
||||||
|
|
||||||
|
|
||||||
def create_services(attrs=None, count=2):
|
def create_services(attrs=None, count=2):
|
||||||
@ -661,10 +639,8 @@ def create_services(attrs=None, count=2):
|
|||||||
def create_one_flavor(attrs=None):
|
def create_one_flavor(attrs=None):
|
||||||
"""Create a fake flavor.
|
"""Create a fake flavor.
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:return: A fake openstack.compute.v2.flavor.Flavor object
|
||||||
:return:
|
|
||||||
A FakeResource object, with id, name, ram, vcpus, and so on
|
|
||||||
"""
|
"""
|
||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
|
|
||||||
@ -695,12 +671,9 @@ def create_one_flavor(attrs=None):
|
|||||||
def create_flavors(attrs=None, count=2):
|
def create_flavors(attrs=None, count=2):
|
||||||
"""Create multiple fake flavors.
|
"""Create multiple fake flavors.
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:param int count: The number of flavors to fake
|
||||||
:param int count:
|
:return: A list of fake openstack.compute.v2.flavor.Flavor objects
|
||||||
The number of flavors to fake
|
|
||||||
:return:
|
|
||||||
A list of FakeResource objects faking the flavors
|
|
||||||
"""
|
"""
|
||||||
flavors = []
|
flavors = []
|
||||||
for i in range(0, count):
|
for i in range(0, count):
|
||||||
@ -715,12 +688,10 @@ def get_flavors(flavors=None, count=2):
|
|||||||
If flavors list is provided, then initialize the Mock object with the
|
If flavors list is provided, then initialize the Mock object with the
|
||||||
list. Otherwise create one.
|
list. Otherwise create one.
|
||||||
|
|
||||||
:param List flavors:
|
:param list flavors: A list of fake openstack.compute.v2.flavor.Flavor
|
||||||
A list of FakeResource objects faking flavors
|
objects
|
||||||
:param int count:
|
:param int count: The number of flavors to fake
|
||||||
The number of flavors to fake
|
:return: An iterable Mock object with side_effect set to a list of faked
|
||||||
:return:
|
|
||||||
An iterable Mock object with side_effect set to a list of faked
|
|
||||||
flavors
|
flavors
|
||||||
"""
|
"""
|
||||||
if flavors is None:
|
if flavors is None:
|
||||||
@ -757,10 +728,8 @@ def create_one_flavor_access(attrs=None):
|
|||||||
def create_one_keypair(attrs=None):
|
def create_one_keypair(attrs=None):
|
||||||
"""Create a fake keypair
|
"""Create a fake keypair
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:return: A fake openstack.compute.v2.keypair.Keypair object
|
||||||
:return:
|
|
||||||
A FakeResource object, name, fingerprint, and so on
|
|
||||||
"""
|
"""
|
||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
|
|
||||||
@ -776,20 +745,15 @@ def create_one_keypair(attrs=None):
|
|||||||
# Overwrite default attributes.
|
# Overwrite default attributes.
|
||||||
keypair_info.update(attrs)
|
keypair_info.update(attrs)
|
||||||
|
|
||||||
keypair = fakes.FakeResource(info=copy.deepcopy(keypair_info), loaded=True)
|
return _keypair.Keypair(**keypair_info)
|
||||||
|
|
||||||
return keypair
|
|
||||||
|
|
||||||
|
|
||||||
def create_keypairs(attrs=None, count=2):
|
def create_keypairs(attrs=None, count=2):
|
||||||
"""Create multiple fake keypairs.
|
"""Create multiple fake keypairs.
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:param int count: The number of keypairs to fake
|
||||||
:param int count:
|
:return: A list of fake openstack.compute.v2.keypair.Keypair objects
|
||||||
The number of keypairs to fake
|
|
||||||
:return:
|
|
||||||
A list of FakeResource objects faking the keypairs
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
keypairs = []
|
keypairs = []
|
||||||
@ -805,12 +769,10 @@ def get_keypairs(keypairs=None, count=2):
|
|||||||
If keypairs list is provided, then initialize the Mock object with the
|
If keypairs list is provided, then initialize the Mock object with the
|
||||||
list. Otherwise create one.
|
list. Otherwise create one.
|
||||||
|
|
||||||
:param List keypairs:
|
:param list keypairs: A list of fake openstack.compute.v2.keypair.Keypair
|
||||||
A list of FakeResource objects faking keypairs
|
objects
|
||||||
:param int count:
|
:param int count: The number of keypairs to fake
|
||||||
The number of keypairs to fake
|
:return: An iterable Mock object with side_effect set to a list of faked
|
||||||
:return:
|
|
||||||
An iterable Mock object with side_effect set to a list of faked
|
|
||||||
keypairs
|
keypairs
|
||||||
"""
|
"""
|
||||||
if keypairs is None:
|
if keypairs is None:
|
||||||
@ -1122,7 +1084,7 @@ def create_one_usage(attrs=None):
|
|||||||
|
|
||||||
# Set default attributes.
|
# Set default attributes.
|
||||||
usage_info = {
|
usage_info = {
|
||||||
'tenant_id': 'usage-tenant-id-' + uuid.uuid4().hex,
|
'project_id': 'usage-tenant-id-' + uuid.uuid4().hex,
|
||||||
'total_memory_mb_usage': 512.0,
|
'total_memory_mb_usage': 512.0,
|
||||||
'total_vcpus_usage': 1.0,
|
'total_vcpus_usage': 1.0,
|
||||||
'total_local_gb_usage': 1.0,
|
'total_local_gb_usage': 1.0,
|
||||||
@ -1145,9 +1107,7 @@ def create_one_usage(attrs=None):
|
|||||||
# Overwrite default attributes.
|
# Overwrite default attributes.
|
||||||
usage_info.update(attrs)
|
usage_info.update(attrs)
|
||||||
|
|
||||||
usage = fakes.FakeResource(info=copy.deepcopy(usage_info), loaded=True)
|
return _usage.Usage(**usage_info)
|
||||||
|
|
||||||
return usage
|
|
||||||
|
|
||||||
|
|
||||||
def create_usages(attrs=None, count=2):
|
def create_usages(attrs=None, count=2):
|
||||||
@ -1511,7 +1471,7 @@ def create_one_volume_attachment(attrs=None):
|
|||||||
# Overwrite default attributes.
|
# Overwrite default attributes.
|
||||||
volume_attachment_info.update(attrs)
|
volume_attachment_info.update(attrs)
|
||||||
|
|
||||||
return volume_attachment.VolumeAttachment(**volume_attachment_info)
|
return _volume_attachment.VolumeAttachment(**volume_attachment_info)
|
||||||
|
|
||||||
|
|
||||||
def create_volume_attachments(attrs=None, count=2):
|
def create_volume_attachments(attrs=None, count=2):
|
||||||
@ -1532,10 +1492,8 @@ def create_volume_attachments(attrs=None, count=2):
|
|||||||
def create_one_hypervisor(attrs=None):
|
def create_one_hypervisor(attrs=None):
|
||||||
"""Create a fake hypervisor.
|
"""Create a fake hypervisor.
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:return: A fake openstack.compute.v2.hypervisor.Hypervisor object
|
||||||
:return:
|
|
||||||
A FakeResource object, with id, hypervisor_hostname, and so on
|
|
||||||
"""
|
"""
|
||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
|
|
||||||
@ -1579,12 +1537,9 @@ def create_one_hypervisor(attrs=None):
|
|||||||
def create_hypervisors(attrs=None, count=2):
|
def create_hypervisors(attrs=None, count=2):
|
||||||
"""Create multiple fake hypervisors.
|
"""Create multiple fake hypervisors.
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:param int count: The number of hypervisors to fake
|
||||||
:param int count:
|
:return: A list of fake openstack.compute.v2.hypervisor.Hypervisor objects
|
||||||
The number of hypervisors to fake
|
|
||||||
:return:
|
|
||||||
A list of FakeResource objects faking the hypervisors
|
|
||||||
"""
|
"""
|
||||||
hypervisors = []
|
hypervisors = []
|
||||||
for i in range(0, count):
|
for i in range(0, count):
|
||||||
@ -1596,10 +1551,8 @@ def create_hypervisors(attrs=None, count=2):
|
|||||||
def create_one_server_group(attrs=None):
|
def create_one_server_group(attrs=None):
|
||||||
"""Create a fake server group
|
"""Create a fake server group
|
||||||
|
|
||||||
:param dict attrs:
|
:param dict attrs: A dictionary with all attributes
|
||||||
A dictionary with all attributes
|
:return: A fake openstack.compute.v2.server_group.ServerGroup object
|
||||||
:return:
|
|
||||||
A fake ServerGroup object, with id and other attributes
|
|
||||||
"""
|
"""
|
||||||
if attrs is None:
|
if attrs is None:
|
||||||
attrs = {}
|
attrs = {}
|
||||||
@ -1626,7 +1579,8 @@ def create_one_server_interface(attrs=None):
|
|||||||
|
|
||||||
:param dict attrs: A dictionary with all attributes
|
:param dict attrs: A dictionary with all attributes
|
||||||
:param dict methods: A dictionary with all methods
|
:param dict methods: A dictionary with all methods
|
||||||
:return: A fake ServerInterface object with various attributes set
|
:return: A fake openstack.compute.v2.server_interface.ServerInterface
|
||||||
|
object
|
||||||
"""
|
"""
|
||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
|
|
||||||
|
@ -31,18 +31,28 @@ class TestAggregate(compute_fakes.TestComputev2):
|
|||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
'availability_zone',
|
'availability_zone',
|
||||||
|
'created_at',
|
||||||
|
'deleted_at',
|
||||||
'hosts',
|
'hosts',
|
||||||
'id',
|
'id',
|
||||||
|
'is_deleted',
|
||||||
'name',
|
'name',
|
||||||
'properties',
|
'properties',
|
||||||
|
'updated_at',
|
||||||
|
'uuid',
|
||||||
)
|
)
|
||||||
|
|
||||||
data = (
|
data = (
|
||||||
fake_ag.availability_zone,
|
fake_ag.availability_zone,
|
||||||
|
fake_ag.created_at,
|
||||||
|
fake_ag.deleted_at,
|
||||||
format_columns.ListColumn(fake_ag.hosts),
|
format_columns.ListColumn(fake_ag.hosts),
|
||||||
fake_ag.id,
|
fake_ag.id,
|
||||||
|
fake_ag.is_deleted,
|
||||||
fake_ag.name,
|
fake_ag.name,
|
||||||
format_columns.DictColumn(fake_ag.metadata),
|
format_columns.DictColumn(fake_ag.metadata),
|
||||||
|
fake_ag.updated_at,
|
||||||
|
fake_ag.uuid,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -488,24 +498,28 @@ class TestAggregateSet(TestAggregate):
|
|||||||
class TestAggregateShow(TestAggregate):
|
class TestAggregateShow(TestAggregate):
|
||||||
columns = (
|
columns = (
|
||||||
'availability_zone',
|
'availability_zone',
|
||||||
|
'created_at',
|
||||||
|
'deleted_at',
|
||||||
'hosts',
|
'hosts',
|
||||||
'id',
|
'id',
|
||||||
|
'is_deleted',
|
||||||
'name',
|
'name',
|
||||||
'properties',
|
'properties',
|
||||||
|
'updated_at',
|
||||||
|
'uuid',
|
||||||
)
|
)
|
||||||
|
|
||||||
data = (
|
data = (
|
||||||
TestAggregate.fake_ag.availability_zone,
|
TestAggregate.fake_ag.availability_zone,
|
||||||
|
TestAggregate.fake_ag.created_at,
|
||||||
|
TestAggregate.fake_ag.deleted_at,
|
||||||
format_columns.ListColumn(TestAggregate.fake_ag.hosts),
|
format_columns.ListColumn(TestAggregate.fake_ag.hosts),
|
||||||
TestAggregate.fake_ag.id,
|
TestAggregate.fake_ag.id,
|
||||||
|
TestAggregate.fake_ag.is_deleted,
|
||||||
TestAggregate.fake_ag.name,
|
TestAggregate.fake_ag.name,
|
||||||
format_columns.DictColumn(
|
format_columns.DictColumn(TestAggregate.fake_ag.metadata),
|
||||||
{
|
TestAggregate.fake_ag.updated_at,
|
||||||
key: value
|
TestAggregate.fake_ag.uuid,
|
||||||
for key, value in TestAggregate.fake_ag.metadata.items()
|
|
||||||
if key != 'availability_zone'
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -57,9 +57,20 @@ class TestKeypairCreate(TestKeypair):
|
|||||||
|
|
||||||
self.keypair = compute_fakes.create_one_keypair()
|
self.keypair = compute_fakes.create_one_keypair()
|
||||||
|
|
||||||
self.columns = ('fingerprint', 'name', 'type', 'user_id')
|
self.columns = (
|
||||||
|
'created_at',
|
||||||
|
'fingerprint',
|
||||||
|
'id',
|
||||||
|
'is_deleted',
|
||||||
|
'name',
|
||||||
|
'type',
|
||||||
|
'user_id',
|
||||||
|
)
|
||||||
self.data = (
|
self.data = (
|
||||||
|
self.keypair.created_at,
|
||||||
self.keypair.fingerprint,
|
self.keypair.fingerprint,
|
||||||
|
self.keypair.id,
|
||||||
|
self.keypair.is_deleted,
|
||||||
self.keypair.name,
|
self.keypair.name,
|
||||||
self.keypair.type,
|
self.keypair.type,
|
||||||
self.keypair.user_id,
|
self.keypair.user_id,
|
||||||
@ -75,7 +86,7 @@ class TestKeypairCreate(TestKeypair):
|
|||||||
'_generate_keypair',
|
'_generate_keypair',
|
||||||
return_value=keypair.Keypair('private', 'public'),
|
return_value=keypair.Keypair('private', 'public'),
|
||||||
)
|
)
|
||||||
def test_key_pair_create_no_options(self, mock_generate):
|
def test_keypair_create_no_options(self, mock_generate):
|
||||||
arglist = [
|
arglist = [
|
||||||
self.keypair.name,
|
self.keypair.name,
|
||||||
]
|
]
|
||||||
@ -96,7 +107,10 @@ class TestKeypairCreate(TestKeypair):
|
|||||||
|
|
||||||
def test_keypair_create_public_key(self):
|
def test_keypair_create_public_key(self):
|
||||||
self.data = (
|
self.data = (
|
||||||
|
self.keypair.created_at,
|
||||||
self.keypair.fingerprint,
|
self.keypair.fingerprint,
|
||||||
|
self.keypair.id,
|
||||||
|
self.keypair.is_deleted,
|
||||||
self.keypair.name,
|
self.keypair.name,
|
||||||
self.keypair.type,
|
self.keypair.type,
|
||||||
self.keypair.user_id,
|
self.keypair.user_id,
|
||||||
@ -173,7 +187,10 @@ class TestKeypairCreate(TestKeypair):
|
|||||||
self.sdk_client.create_keypair.return_value = self.keypair
|
self.sdk_client.create_keypair.return_value = self.keypair
|
||||||
|
|
||||||
self.data = (
|
self.data = (
|
||||||
|
self.keypair.created_at,
|
||||||
self.keypair.fingerprint,
|
self.keypair.fingerprint,
|
||||||
|
self.keypair.id,
|
||||||
|
self.keypair.is_deleted,
|
||||||
self.keypair.name,
|
self.keypair.name,
|
||||||
self.keypair.type,
|
self.keypair.type,
|
||||||
self.keypair.user_id,
|
self.keypair.user_id,
|
||||||
@ -291,7 +308,7 @@ class TestKeypairDelete(TestKeypair):
|
|||||||
keypairs = compute_fakes.create_keypairs(count=2)
|
keypairs = compute_fakes.create_keypairs(count=2)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestKeypairDelete, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.cmd = keypair.DeleteKeypair(self.app, None)
|
self.cmd = keypair.DeleteKeypair(self.app, None)
|
||||||
|
|
||||||
@ -397,7 +414,7 @@ class TestKeypairList(TestKeypair):
|
|||||||
keypairs = compute_fakes.create_keypairs(count=1)
|
keypairs = compute_fakes.create_keypairs(count=1)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestKeypairList, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.sdk_client.keypairs.return_value = self.keypairs
|
self.sdk_client.keypairs.return_value = self.keypairs
|
||||||
|
|
||||||
@ -661,24 +678,22 @@ class TestKeypairList(TestKeypair):
|
|||||||
|
|
||||||
|
|
||||||
class TestKeypairShow(TestKeypair):
|
class TestKeypairShow(TestKeypair):
|
||||||
keypair = compute_fakes.create_one_keypair()
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestKeypairShow, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.sdk_client.find_keypair.return_value = self.keypair
|
self.columns = (
|
||||||
|
'created_at',
|
||||||
|
'fingerprint',
|
||||||
|
'id',
|
||||||
|
'is_deleted',
|
||||||
|
'name',
|
||||||
|
'private_key',
|
||||||
|
'type',
|
||||||
|
'user_id',
|
||||||
|
)
|
||||||
|
|
||||||
self.cmd = keypair.ShowKeypair(self.app, None)
|
self.cmd = keypair.ShowKeypair(self.app, None)
|
||||||
|
|
||||||
self.columns = ("fingerprint", "name", "type", "user_id")
|
|
||||||
|
|
||||||
self.data = (
|
|
||||||
self.keypair.fingerprint,
|
|
||||||
self.keypair.name,
|
|
||||||
self.keypair.type,
|
|
||||||
self.keypair.user_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_keypair_show_no_options(self):
|
def test_keypair_show_no_options(self):
|
||||||
arglist = []
|
arglist = []
|
||||||
verifylist = []
|
verifylist = []
|
||||||
@ -693,11 +708,16 @@ class TestKeypairShow(TestKeypair):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_keypair_show(self):
|
def test_keypair_show(self):
|
||||||
|
self.keypair = compute_fakes.create_one_keypair()
|
||||||
self.sdk_client.find_keypair.return_value = self.keypair
|
self.sdk_client.find_keypair.return_value = self.keypair
|
||||||
|
|
||||||
self.data = (
|
self.data = (
|
||||||
|
self.keypair.created_at,
|
||||||
self.keypair.fingerprint,
|
self.keypair.fingerprint,
|
||||||
|
self.keypair.id,
|
||||||
|
self.keypair.is_deleted,
|
||||||
self.keypair.name,
|
self.keypair.name,
|
||||||
|
self.keypair.private_key,
|
||||||
self.keypair.type,
|
self.keypair.type,
|
||||||
self.keypair.user_id,
|
self.keypair.user_id,
|
||||||
)
|
)
|
||||||
@ -716,6 +736,9 @@ class TestKeypairShow(TestKeypair):
|
|||||||
self.assertEqual(self.data, data)
|
self.assertEqual(self.data, data)
|
||||||
|
|
||||||
def test_keypair_show_public(self):
|
def test_keypair_show_public(self):
|
||||||
|
self.keypair = compute_fakes.create_one_keypair()
|
||||||
|
self.sdk_client.find_keypair.return_value = self.keypair
|
||||||
|
|
||||||
arglist = ['--public-key', self.keypair.name]
|
arglist = ['--public-key', self.keypair.name]
|
||||||
verifylist = [('public_key', True), ('name', self.keypair.name)]
|
verifylist = [('public_key', True), ('name', self.keypair.name)]
|
||||||
|
|
||||||
@ -728,11 +751,16 @@ class TestKeypairShow(TestKeypair):
|
|||||||
|
|
||||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||||
def test_keypair_show_with_user(self, sm_mock):
|
def test_keypair_show_with_user(self, sm_mock):
|
||||||
|
self.keypair = compute_fakes.create_one_keypair()
|
||||||
self.sdk_client.find_keypair.return_value = self.keypair
|
self.sdk_client.find_keypair.return_value = self.keypair
|
||||||
|
|
||||||
self.data = (
|
self.data = (
|
||||||
|
self.keypair.created_at,
|
||||||
self.keypair.fingerprint,
|
self.keypair.fingerprint,
|
||||||
|
self.keypair.id,
|
||||||
|
self.keypair.is_deleted,
|
||||||
self.keypair.name,
|
self.keypair.name,
|
||||||
|
self.keypair.private_key,
|
||||||
self.keypair.type,
|
self.keypair.type,
|
||||||
self.keypair.user_id,
|
self.keypair.user_id,
|
||||||
)
|
)
|
||||||
@ -762,6 +790,7 @@ class TestKeypairShow(TestKeypair):
|
|||||||
|
|
||||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||||
def test_keypair_show_with_user_pre_v210(self, sm_mock):
|
def test_keypair_show_with_user_pre_v210(self, sm_mock):
|
||||||
|
self.keypair = compute_fakes.create_one_keypair()
|
||||||
arglist = [
|
arglist = [
|
||||||
'--user',
|
'--user',
|
||||||
identity_fakes.user_name,
|
identity_fakes.user_name,
|
||||||
@ -774,8 +803,11 @@ class TestKeypairShow(TestKeypair):
|
|||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
ex = self.assertRaises(
|
ex = self.assertRaises(
|
||||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args,
|
||||||
)
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'--os-compute-api-version 2.10 or greater is required', str(ex)
|
'--os-compute-api-version 2.10 or greater is required',
|
||||||
|
str(ex),
|
||||||
)
|
)
|
||||||
|
@ -161,7 +161,6 @@ class TestServer(compute_fakes.TestComputev2):
|
|||||||
def setup_sdk_servers_mock(self, count):
|
def setup_sdk_servers_mock(self, count):
|
||||||
servers = compute_fakes.create_sdk_servers(
|
servers = compute_fakes.create_sdk_servers(
|
||||||
attrs=self.attrs,
|
attrs=self.attrs,
|
||||||
methods=self.methods,
|
|
||||||
count=count,
|
count=count,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,13 +38,9 @@ class TestServerBackup(compute_fakes.TestComputev2):
|
|||||||
# Set object attributes to be tested. Could be overwritten in subclass.
|
# Set object attributes to be tested. Could be overwritten in subclass.
|
||||||
self.attrs = {}
|
self.attrs = {}
|
||||||
|
|
||||||
# Set object methods to be tested. Could be overwritten in subclass.
|
|
||||||
self.methods = {}
|
|
||||||
|
|
||||||
def setup_servers_mock(self, count):
|
def setup_servers_mock(self, count):
|
||||||
servers = compute_fakes.create_sdk_servers(
|
servers = compute_fakes.create_sdk_servers(
|
||||||
attrs=self.attrs,
|
attrs=self.attrs,
|
||||||
methods=self.methods,
|
|
||||||
count=count,
|
count=count,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -89,10 +85,6 @@ class TestServerBackupCreate(TestServerBackup):
|
|||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
self.cmd = server_backup.CreateServerBackup(self.app, None)
|
self.cmd = server_backup.CreateServerBackup(self.app, None)
|
||||||
|
|
||||||
self.methods = {
|
|
||||||
'backup': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
def setup_images_mock(self, count, servers=None):
|
def setup_images_mock(self, count, servers=None):
|
||||||
if servers:
|
if servers:
|
||||||
images = image_fakes.create_images(
|
images = image_fakes.create_images(
|
||||||
|
@ -23,7 +23,7 @@ from openstackclient.tests.unit.image.v2 import fakes as image_fakes
|
|||||||
|
|
||||||
class TestServerImage(compute_fakes.TestComputev2):
|
class TestServerImage(compute_fakes.TestComputev2):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestServerImage, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
# Get a shortcut to the compute client ServerManager Mock
|
# Get a shortcut to the compute client ServerManager Mock
|
||||||
self.app.client_manager.sdk_connection = mock.Mock()
|
self.app.client_manager.sdk_connection = mock.Mock()
|
||||||
@ -37,13 +37,9 @@ class TestServerImage(compute_fakes.TestComputev2):
|
|||||||
# Set object attributes to be tested. Could be overwritten in subclass.
|
# Set object attributes to be tested. Could be overwritten in subclass.
|
||||||
self.attrs = {}
|
self.attrs = {}
|
||||||
|
|
||||||
# Set object methods to be tested. Could be overwritten in subclass.
|
|
||||||
self.methods = {}
|
|
||||||
|
|
||||||
def setup_servers_mock(self, count):
|
def setup_servers_mock(self, count):
|
||||||
servers = compute_fakes.create_sdk_servers(
|
servers = compute_fakes.create_sdk_servers(
|
||||||
attrs=self.attrs,
|
attrs=self.attrs,
|
||||||
methods=self.methods,
|
|
||||||
count=count,
|
count=count,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,15 +78,11 @@ class TestServerImageCreate(TestServerImage):
|
|||||||
return datalist
|
return datalist
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestServerImageCreate, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
self.cmd = server_image.CreateServerImage(self.app, None)
|
self.cmd = server_image.CreateServerImage(self.app, None)
|
||||||
|
|
||||||
self.methods = {
|
|
||||||
'create_image': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
def setup_images_mock(self, count, servers=None):
|
def setup_images_mock(self, count, servers=None):
|
||||||
if servers:
|
if servers:
|
||||||
images = image_fakes.create_images(
|
images = image_fakes.create_images(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user