|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +import datetime |
| 14 | + |
| 15 | +import testtools |
| 16 | + |
| 17 | +from openstack.network.v2 import agent |
| 18 | + |
| 19 | +IDENTIFIER = 'IDENTIFIER' |
| 20 | +EXAMPLE = { |
| 21 | + 'admin_state_up': True, |
| 22 | + 'agent_type': 'Test Agent', |
| 23 | + 'alive': True, |
| 24 | + 'availability_zone': 'az1', |
| 25 | + 'binary': 'test-binary', |
| 26 | + 'configurations': {'attr1': 'value1', 'attr2': 'value2'}, |
| 27 | + 'created_at': '2016-03-09T12:14:57.233772', |
| 28 | + 'description': 'test description', |
| 29 | + 'heartbeat_timestamp': '2016-08-09T12:14:57.233772', |
| 30 | + 'host': 'test-host', |
| 31 | + 'id': IDENTIFIER, |
| 32 | + 'started_at': '2016-07-09T12:14:57.233772', |
| 33 | + 'topic': 'test-topic' |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +class TestAgent(testtools.TestCase): |
| 38 | + |
| 39 | + def test_basic(self): |
| 40 | + sot = agent.Agent() |
| 41 | + self.assertEqual('agent', sot.resource_key) |
| 42 | + self.assertEqual('agents', sot.resources_key) |
| 43 | + self.assertEqual('/agents', sot.base_path) |
| 44 | + self.assertEqual('network', sot.service.service_type) |
| 45 | + self.assertFalse(sot.allow_create) |
| 46 | + self.assertTrue(sot.allow_retrieve) |
| 47 | + self.assertTrue(sot.allow_update) |
| 48 | + self.assertTrue(sot.allow_delete) |
| 49 | + self.assertTrue(sot.allow_list) |
| 50 | + |
| 51 | + def test_make_it(self): |
| 52 | + sot = agent.Agent(EXAMPLE) |
| 53 | + self.assertTrue(sot.is_admin_state_up) |
| 54 | + self.assertEqual(EXAMPLE['agent_type'], sot.agent_type) |
| 55 | + self.assertTrue(sot.is_alive) |
| 56 | + self.assertEqual(EXAMPLE['availability_zone'], |
| 57 | + sot.availability_zone) |
| 58 | + self.assertEqual(EXAMPLE['binary'], sot.binary) |
| 59 | + self.assertEqual(EXAMPLE['configurations'], sot.configuration) |
| 60 | + dt = datetime.datetime(2016, 3, 9, 12, 14, 57, 233772).replace( |
| 61 | + tzinfo=None) |
| 62 | + self.assertEqual(dt, sot.created_at.replace(tzinfo=None)) |
| 63 | + self.assertEqual(EXAMPLE['description'], sot.description) |
| 64 | + dt = datetime.datetime(2016, 8, 9, 12, 14, 57, 233772).replace( |
| 65 | + tzinfo=None) |
| 66 | + self.assertEqual(dt, |
| 67 | + sot.last_heartbeat_at.replace(tzinfo=None)) |
| 68 | + self.assertEqual(EXAMPLE['host'], sot.host) |
| 69 | + self.assertEqual(EXAMPLE['id'], sot.id) |
| 70 | + dt = datetime.datetime(2016, 7, 9, 12, 14, 57, 233772).replace( |
| 71 | + tzinfo=None) |
| 72 | + self.assertEqual(dt, sot.started_at.replace(tzinfo=None)) |
| 73 | + self.assertEqual(EXAMPLE['topic'], sot.topic) |
0 commit comments