Adopt sdk_fakes for compute.aggregate
Drop fakes generation for compute aggregates in favor of sdk_fakes Change-Id: I4965a5fe8fc3d70390ca0268716519b617ca24eb
This commit is contained in:
parent
52b2944b78
commit
329b351cb8
@ -21,7 +21,6 @@ import uuid
|
|||||||
|
|
||||||
from keystoneauth1 import discover
|
from keystoneauth1 import discover
|
||||||
from openstack.compute.v2 import _proxy
|
from openstack.compute.v2 import _proxy
|
||||||
from openstack.compute.v2 import aggregate as _aggregate
|
|
||||||
from openstack.compute.v2 import availability_zone as _availability_zone
|
from openstack.compute.v2 import availability_zone as _availability_zone
|
||||||
from openstack.compute.v2 import extension as _extension
|
from openstack.compute.v2 import extension as _extension
|
||||||
from openstack.compute.v2 import flavor as _flavor
|
from openstack.compute.v2 import flavor as _flavor
|
||||||
@ -142,63 +141,6 @@ class TestComputev2(
|
|||||||
): ...
|
): ...
|
||||||
|
|
||||||
|
|
||||||
def create_one_aggregate(attrs=None):
|
|
||||||
"""Create a fake aggregate.
|
|
||||||
|
|
||||||
:param dict attrs: A dictionary with all attributes
|
|
||||||
:return: A fake openstack.compute.v2.aggregate.Aggregate object
|
|
||||||
"""
|
|
||||||
attrs = attrs or {}
|
|
||||||
|
|
||||||
# Set default attribute
|
|
||||||
aggregate_info = {
|
|
||||||
"name": "aggregate-name-" + uuid.uuid4().hex,
|
|
||||||
"availability_zone": "ag_zone",
|
|
||||||
"hosts": [],
|
|
||||||
"id": "aggregate-id-" + uuid.uuid4().hex,
|
|
||||||
"metadata": {
|
|
||||||
"availability_zone": "ag_zone",
|
|
||||||
"key1": "value1",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
# Overwrite default attributes.
|
|
||||||
aggregate_info.update(attrs)
|
|
||||||
|
|
||||||
aggregate = _aggregate.Aggregate(**aggregate_info)
|
|
||||||
return aggregate
|
|
||||||
|
|
||||||
|
|
||||||
def create_aggregates(attrs=None, count=2):
|
|
||||||
"""Create multiple fake aggregates.
|
|
||||||
|
|
||||||
:param dict attrs: A dictionary with all attributes
|
|
||||||
:param int count: The number of aggregates to fake
|
|
||||||
:return: A list of fake openstack.compute.v2.aggregate.Aggregate objects
|
|
||||||
"""
|
|
||||||
aggregates = []
|
|
||||||
for i in range(0, count):
|
|
||||||
aggregates.append(create_one_aggregate(attrs))
|
|
||||||
|
|
||||||
return aggregates
|
|
||||||
|
|
||||||
|
|
||||||
def get_aggregates(aggregates=None, count=2):
|
|
||||||
"""Get an iterable MagicMock object with a list of faked aggregates.
|
|
||||||
|
|
||||||
If aggregates list is provided, then initialize the Mock object
|
|
||||||
with the list. Otherwise create one.
|
|
||||||
|
|
||||||
:return: A list of fake openstack.compute.v2.aggregate.Aggregate objects
|
|
||||||
:param int count: The number of aggregates to fake
|
|
||||||
:return: An iterable Mock object with side_effect set to a list of faked
|
|
||||||
aggregates
|
|
||||||
"""
|
|
||||||
if aggregates is None:
|
|
||||||
aggregates = create_aggregates(count)
|
|
||||||
return mock.Mock(side_effect=aggregates)
|
|
||||||
|
|
||||||
|
|
||||||
def create_one_agent(attrs=None):
|
def create_one_agent(attrs=None):
|
||||||
"""Create a fake agent.
|
"""Create a fake agent.
|
||||||
|
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
from unittest.mock import call
|
from unittest.mock import call
|
||||||
|
|
||||||
|
from openstack.compute.v2 import aggregate as _aggregate
|
||||||
from openstack import exceptions as sdk_exceptions
|
from openstack import exceptions as sdk_exceptions
|
||||||
|
from openstack.test import fakes as sdk_fakes
|
||||||
from osc_lib.cli import format_columns
|
from osc_lib.cli import format_columns
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
|
|
||||||
@ -26,8 +28,6 @@ from openstackclient.tests.unit.image.v2 import fakes as image_fakes
|
|||||||
|
|
||||||
|
|
||||||
class TestAggregate(compute_fakes.TestComputev2):
|
class TestAggregate(compute_fakes.TestComputev2):
|
||||||
fake_ag = compute_fakes.create_one_aggregate()
|
|
||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
'availability_zone',
|
'availability_zone',
|
||||||
'created_at',
|
'created_at',
|
||||||
@ -41,17 +41,24 @@ class TestAggregate(compute_fakes.TestComputev2):
|
|||||||
'uuid',
|
'uuid',
|
||||||
)
|
)
|
||||||
|
|
||||||
data = (
|
def setUp(self):
|
||||||
fake_ag.availability_zone,
|
super().setUp()
|
||||||
fake_ag.created_at,
|
|
||||||
fake_ag.deleted_at,
|
self.fake_ag = sdk_fakes.generate_fake_resource(
|
||||||
format_columns.ListColumn(fake_ag.hosts),
|
_aggregate.Aggregate,
|
||||||
fake_ag.id,
|
metadata={'availability_zone': 'ag_zone', 'key1': 'value1'},
|
||||||
fake_ag.is_deleted,
|
)
|
||||||
fake_ag.name,
|
self.data = (
|
||||||
format_columns.DictColumn(fake_ag.metadata),
|
self.fake_ag.availability_zone,
|
||||||
fake_ag.updated_at,
|
self.fake_ag.created_at,
|
||||||
fake_ag.uuid,
|
self.fake_ag.deleted_at,
|
||||||
|
format_columns.ListColumn(self.fake_ag.hosts),
|
||||||
|
self.fake_ag.id,
|
||||||
|
self.fake_ag.is_deleted,
|
||||||
|
self.fake_ag.name,
|
||||||
|
format_columns.DictColumn(self.fake_ag.metadata),
|
||||||
|
self.fake_ag.updated_at,
|
||||||
|
self.fake_ag.uuid,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -155,13 +162,15 @@ class TestAggregateCreate(TestAggregate):
|
|||||||
|
|
||||||
|
|
||||||
class TestAggregateDelete(TestAggregate):
|
class TestAggregateDelete(TestAggregate):
|
||||||
fake_ags = compute_fakes.create_aggregates(count=2)
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.compute_sdk_client.find_aggregate = compute_fakes.get_aggregates(
|
self.fake_ags = list(
|
||||||
self.fake_ags
|
sdk_fakes.generate_fake_resources(_aggregate.Aggregate, 2)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.compute_sdk_client.find_aggregate = mock.Mock(
|
||||||
|
side_effect=[self.fake_ags[0], self.fake_ags[1]]
|
||||||
)
|
)
|
||||||
self.cmd = aggregate.DeleteAggregate(self.app, None)
|
self.cmd = aggregate.DeleteAggregate(self.app, None)
|
||||||
|
|
||||||
@ -526,25 +535,25 @@ class TestAggregateShow(TestAggregate):
|
|||||||
'uuid',
|
'uuid',
|
||||||
)
|
)
|
||||||
|
|
||||||
data = (
|
|
||||||
TestAggregate.fake_ag.availability_zone,
|
|
||||||
TestAggregate.fake_ag.created_at,
|
|
||||||
TestAggregate.fake_ag.deleted_at,
|
|
||||||
format_columns.ListColumn(TestAggregate.fake_ag.hosts),
|
|
||||||
TestAggregate.fake_ag.id,
|
|
||||||
TestAggregate.fake_ag.is_deleted,
|
|
||||||
TestAggregate.fake_ag.name,
|
|
||||||
format_columns.DictColumn(TestAggregate.fake_ag.metadata),
|
|
||||||
TestAggregate.fake_ag.updated_at,
|
|
||||||
TestAggregate.fake_ag.uuid,
|
|
||||||
)
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.compute_sdk_client.find_aggregate.return_value = self.fake_ag
|
self.compute_sdk_client.find_aggregate.return_value = self.fake_ag
|
||||||
self.cmd = aggregate.ShowAggregate(self.app, None)
|
self.cmd = aggregate.ShowAggregate(self.app, None)
|
||||||
|
|
||||||
|
self.data = (
|
||||||
|
self.fake_ag.availability_zone,
|
||||||
|
self.fake_ag.created_at,
|
||||||
|
self.fake_ag.deleted_at,
|
||||||
|
format_columns.ListColumn(self.fake_ag.hosts),
|
||||||
|
self.fake_ag.id,
|
||||||
|
self.fake_ag.is_deleted,
|
||||||
|
self.fake_ag.name,
|
||||||
|
format_columns.DictColumn(self.fake_ag.metadata),
|
||||||
|
self.fake_ag.updated_at,
|
||||||
|
self.fake_ag.uuid,
|
||||||
|
)
|
||||||
|
|
||||||
def test_aggregate_show(self):
|
def test_aggregate_show(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'ag1',
|
'ag1',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user