diff options
| author | Jenkins <jenkins@review.openstack.org> | 2016-05-31 07:11:04 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2016-05-31 07:11:04 +0000 |
| commit | ca58ab9d0971200a34c84a96d80a1c12a9314096 (patch) | |
| tree | b20a3a2dfc3efa7d92285b365ecc937e01513855 /openstackclient/tests/compute/v2/fakes.py | |
| parent | 8470618611829338e3cd46f008b388e9866ea422 (diff) | |
| parent | a207fdfda6e4f888c730c89288a64fcb3c491ea2 (diff) | |
| download | python-openstackclient-ca58ab9d0971200a34c84a96d80a1c12a9314096.tar.gz | |
Merge "add unit test for compute agent command"
Diffstat (limited to 'openstackclient/tests/compute/v2/fakes.py')
| -rw-r--r-- | openstackclient/tests/compute/v2/fakes.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index 505469ad..c9e2025d 100644 --- a/openstackclient/tests/compute/v2/fakes.py +++ b/openstackclient/tests/compute/v2/fakes.py @@ -111,6 +111,9 @@ class FakeAggregate(object): class FakeComputev2Client(object): def __init__(self, **kwargs): + self.agents = mock.Mock() + self.agents.resource_class = fakes.FakeResource(None, {}) + self.aggregates = mock.Mock() self.aggregates.resource_class = fakes.FakeResource(None, {}) @@ -207,6 +210,55 @@ class TestComputev2(utils.TestCommand): ) +class FakeAgent(object): + """Fake one or more agent.""" + + @staticmethod + def create_one_agent(attrs=None): + """Create a fake agent. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object, with agent_id, os, and so on + """ + + attrs = attrs or {} + + # set default attributes. + agent_info = { + 'agent_id': 'agent-id-' + uuid.uuid4().hex, + 'os': 'agent-os-' + uuid.uuid4().hex, + 'architecture': 'agent-architecture', + 'version': '8.0', + 'url': 'http://127.0.0.1', + 'md5hash': 'agent-md5hash', + 'hypervisor': 'hypervisor', + } + agent_info.update(attrs) + + agent = fakes.FakeResource(info=copy.deepcopy(agent_info), + loaded=True) + return agent + + @staticmethod + def create_agents(attrs=None, count=2): + """Create multiple fake agents. + + :param Dictionary attrs: + A dictionary with all attributes + :param int count: + The number of agents to fake + :return: + A list of FakeResource objects faking the agents + """ + agents = [] + for i in range(0, count): + agents.append(FakeAgent.create_one_agent(attrs)) + + return agents + + class FakeHypervisor(object): """Fake one or more hypervisor.""" |
