|
| 1 | +""" |
| 2 | + SoftLayer.tests.CLI.modules.hardware.hardware_list_tests |
| 3 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4 | +
|
| 5 | + These tests the `slcli hw list` command. Its complex enough to warrant its own file |
| 6 | +
|
| 7 | + :license: MIT, see LICENSE for more details. |
| 8 | +""" |
| 9 | + |
| 10 | +import json |
| 11 | + |
| 12 | +from SoftLayer import testing |
| 13 | +from SoftLayer import utils |
| 14 | + |
| 15 | + |
| 16 | +class HardwareListCLITests(testing.TestCase): |
| 17 | + def test_list_servers(self): |
| 18 | + colums = 'datacenter,primary_ip,hostname,id,backend_ip,action' |
| 19 | + result = self.run_command(['server', 'list', '--tag=openstack', f'--columns={colums}']) |
| 20 | + |
| 21 | + expected = [ |
| 22 | + { |
| 23 | + 'datacenter': 'TEST00', |
| 24 | + 'primary_ip': '172.16.1.100', |
| 25 | + 'hostname': 'hardware-test1', |
| 26 | + 'id': 1000, |
| 27 | + 'backend_ip': '10.1.0.2', |
| 28 | + 'action': 'TXN_NAME', |
| 29 | + }, |
| 30 | + { |
| 31 | + 'datacenter': 'TEST00', |
| 32 | + 'primary_ip': '172.16.4.94', |
| 33 | + 'hostname': 'hardware-test2', |
| 34 | + 'id': 1001, |
| 35 | + 'backend_ip': '10.1.0.3', |
| 36 | + 'action': None, |
| 37 | + }, |
| 38 | + { |
| 39 | + 'datacenter': 'TEST00', |
| 40 | + 'primary_ip': '172.16.4.95', |
| 41 | + 'hostname': 'hardware-bad-memory', |
| 42 | + 'id': 1002, |
| 43 | + 'backend_ip': '10.1.0.4', |
| 44 | + 'action': None, |
| 45 | + }, |
| 46 | + { |
| 47 | + 'action': None, |
| 48 | + 'backend_ip': None, |
| 49 | + 'datacenter': None, |
| 50 | + 'hostname': None, |
| 51 | + 'id': 1003, |
| 52 | + 'primary_ip': None, |
| 53 | + }, |
| 54 | + ] |
| 55 | + |
| 56 | + self.assert_no_fail(result) |
| 57 | + self.assertEqual(expected, json.loads(result.output)) |
| 58 | + |
| 59 | + def test_list_hw_search_noargs(self): |
| 60 | + result = self.run_command(['hw', 'list', '--search']) |
| 61 | + self.assert_no_fail(result) |
| 62 | + self.assert_called_with('SoftLayer_Search', 'advancedSearch', args=('_objectType:SoftLayer_Hardware ',)) |
| 63 | + |
| 64 | + def test_list_hw_search_noargs_domain(self): |
| 65 | + result = self.run_command(['hw', 'list', '--search', '-Dtest']) |
| 66 | + self.assert_no_fail(result) |
| 67 | + self.assert_called_with('SoftLayer_Search', 'advancedSearch', |
| 68 | + args=('_objectType:SoftLayer_Hardware domain: *test*',)) |
| 69 | + |
| 70 | + def test_list_by_owner(self): |
| 71 | + result = self.run_command(['hw', 'list', '--owner=testUser']) |
| 72 | + self.assert_no_fail(result) |
| 73 | + expectedFilter = utils.NestedDict() |
| 74 | + expectedFilter['hardware']['id'] = utils.query_filter_orderby() |
| 75 | + expectedFilter['hardware']['billingItem']['orderItem']['order']['userRecord']['username'] = ( |
| 76 | + utils.query_filter('testUser')) |
| 77 | + self.assert_called_with('SoftLayer_Account', 'getHardware', filter=expectedFilter) |
| 78 | + |
| 79 | + def test_list_by_pub_ip(self): |
| 80 | + result = self.run_command(['hw', 'list', '--primary_ip=1.2.3.4']) |
| 81 | + self.assert_no_fail(result) |
| 82 | + expectedFilter = utils.NestedDict() |
| 83 | + expectedFilter['hardware']['id'] = utils.query_filter_orderby() |
| 84 | + expectedFilter['hardware']['primaryIpAddress'] = utils.query_filter('1.2.3.4') |
| 85 | + self.assert_called_with('SoftLayer_Account', 'getHardware', filter=expectedFilter) |
| 86 | + |
| 87 | + def test_list_by_pri_ip(self): |
| 88 | + result = self.run_command(['hw', 'list', '--backend_ip=1.2.3.4']) |
| 89 | + self.assert_no_fail(result) |
| 90 | + expectedFilter = utils.NestedDict() |
| 91 | + expectedFilter['hardware']['id'] = utils.query_filter_orderby() |
| 92 | + expectedFilter['hardware']['primaryBackendIpAddress'] = utils.query_filter('1.2.3.4') |
| 93 | + self.assert_called_with('SoftLayer_Account', 'getHardware', filter=expectedFilter) |
0 commit comments