diff options
| author | sunyajing <yajing.sun@easystack.cn> | 2016-05-31 10:54:16 +0800 |
|---|---|---|
| committer | sunyajing <yajing.sun@easystack.cn> | 2016-05-31 12:50:23 +0800 |
| commit | a207fdfda6e4f888c730c89288a64fcb3c491ea2 (patch) | |
| tree | 537ded06bfc90eca608c4cc00644007c62a2a3c1 /openstackclient/tests/compute/v2/fakes.py | |
| parent | 9da02d14eadc39da6f97b3df095af8b0c452a5b4 (diff) | |
| download | python-openstackclient-a207fdfda6e4f888c730c89288a64fcb3c491ea2.tar.gz | |
add unit test for compute agent command
Change-Id: I966d5a3a307fcd7f4efb1267aa2896efd53be50d
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 62a46b1d..94964e65 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, {}) @@ -204,6 +207,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.""" |
