Adopt sdk_fakes for compute.test_usage
Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/882682 Change-Id: Ia8fd2ccfd1e86749fdeeb49c2d57de64635cbb82
This commit is contained in:
parent
afc0d3c252
commit
776b7d0c66
openstackclient/tests/unit/compute/v2
@ -32,7 +32,6 @@ 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_interface as _server_interface
|
||||
from openstack.compute.v2 import server_migration as _server_migration
|
||||
from openstack.compute.v2 import usage as _usage
|
||||
from openstack.compute.v2 import volume_attachment as _volume_attachment
|
||||
|
||||
from openstackclient.tests.unit import fakes
|
||||
@ -810,62 +809,6 @@ def get_networks(networks=None, count=2):
|
||||
return mock.Mock(side_effect=networks)
|
||||
|
||||
|
||||
def create_one_usage(attrs=None):
|
||||
"""Create a fake usage.
|
||||
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object, with tenant_id and other attributes
|
||||
"""
|
||||
if attrs is None:
|
||||
attrs = {}
|
||||
|
||||
# Set default attributes.
|
||||
usage_info = {
|
||||
'project_id': 'usage-tenant-id-' + uuid.uuid4().hex,
|
||||
'total_memory_mb_usage': 512.0,
|
||||
'total_vcpus_usage': 1.0,
|
||||
'total_local_gb_usage': 1.0,
|
||||
'server_usages': [
|
||||
{
|
||||
'ended_at': None,
|
||||
'flavor': 'usage-flavor-' + uuid.uuid4().hex,
|
||||
'hours': 1.0,
|
||||
'local_gb': 1,
|
||||
'memory_mb': 512,
|
||||
'name': 'usage-name-' + uuid.uuid4().hex,
|
||||
'instance_id': uuid.uuid4().hex,
|
||||
'state': 'active',
|
||||
'uptime': 3600,
|
||||
'vcpus': 1,
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
# Overwrite default attributes.
|
||||
usage_info.update(attrs)
|
||||
|
||||
return _usage.Usage(**usage_info)
|
||||
|
||||
|
||||
def create_usages(attrs=None, count=2):
|
||||
"""Create multiple fake services.
|
||||
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:param int count:
|
||||
The number of services to fake
|
||||
:return:
|
||||
A list of FakeResource objects faking the services
|
||||
"""
|
||||
usages = []
|
||||
for i in range(0, count):
|
||||
usages.append(create_one_usage(attrs))
|
||||
|
||||
return usages
|
||||
|
||||
|
||||
def create_limits(attrs=None):
|
||||
"""Create a fake limits object."""
|
||||
attrs = attrs or {}
|
||||
|
@ -14,9 +14,12 @@
|
||||
import datetime
|
||||
from unittest import mock
|
||||
|
||||
from openstack.compute.v2 import usage as _usage
|
||||
from openstack.identity.v3 import project as _project
|
||||
from openstack.test import fakes as sdk_fakes
|
||||
|
||||
from openstackclient.compute.v2 import usage as usage_cmds
|
||||
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
||||
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
||||
|
||||
|
||||
class TestUsage(compute_fakes.TestComputev2):
|
||||
@ -28,11 +31,11 @@ class TestUsage(compute_fakes.TestComputev2):
|
||||
|
||||
|
||||
class TestUsageList(TestUsage):
|
||||
project = identity_fakes.FakeProject.create_one_project()
|
||||
project = sdk_fakes.generate_fake_resource(_project.Project)
|
||||
# Return value of self.usage_mock.list().
|
||||
usages = compute_fakes.create_usages(
|
||||
attrs={'project_id': project.name}, count=1
|
||||
)
|
||||
usages = [
|
||||
sdk_fakes.generate_fake_resource(_usage.Usage, project_id=project.name)
|
||||
]
|
||||
|
||||
columns = (
|
||||
"Project",
|
||||
@ -123,9 +126,11 @@ class TestUsageList(TestUsage):
|
||||
|
||||
|
||||
class TestUsageShow(TestUsage):
|
||||
project = identity_fakes.FakeProject.create_one_project()
|
||||
project = sdk_fakes.generate_fake_resource(_project.Project)
|
||||
# Return value of self.usage_mock.list().
|
||||
usage = compute_fakes.create_one_usage(attrs={'project_id': project.name})
|
||||
usage = sdk_fakes.generate_fake_resource(
|
||||
_usage.Usage, project_id=project.name
|
||||
)
|
||||
|
||||
columns = (
|
||||
'Project',
|
||||
|
Loading…
x
Reference in New Issue
Block a user