From 909b97d8d549e43a0ff1b8413b2821ac506d4f4c Mon Sep 17 00:00:00 2001 From: Erick Sapp Date: Thu, 31 May 2018 14:21:18 -0500 Subject: [PATCH 1/5] Added unit test for the detail command with no billing item associated with the returned virtual guest. --- tests/CLI/modules/vs_tests.py | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/CLI/modules/vs_tests.py b/tests/CLI/modules/vs_tests.py index 0b4883902..37e6922d6 100644 --- a/tests/CLI/modules/vs_tests.py +++ b/tests/CLI/modules/vs_tests.py @@ -154,6 +154,54 @@ def test_list_vs(self): 'id': 104, 'backend_ip': '10.45.19.35'}]) + @mock.patch('SoftLayer.utils.lookup') + def test_detail_vs_empty_billing(self, mock_lookup): + def mock_lookup_func(dic, key, *keys): + if key == 'billingItem': + return [] + if keys: + return mock_lookup_func(dic.get(key, {}), keys[0], *keys[1:]) + return dic.get(key) + + mock_lookup.side_effect = mock_lookup_func + + result = self.run_command(['vs', 'detail', '100', '--passwords', '--price']) + + self.assert_no_fail(result) + self.assertEqual(json.loads(result.output), + {'active_transaction': None, + 'cores': 2, + 'created': '2013-08-01 15:23:45', + 'datacenter': 'TEST00', + 'dedicated_host': 'test-dedicated', + 'dedicated_host_id': 37401, + 'hostname': 'vs-test1', + 'domain': 'test.sftlyr.ws', + 'fqdn': 'vs-test1.test.sftlyr.ws', + 'id': 100, + 'guid': '1a2b3c-1701', + 'memory': 1024, + 'modified': {}, + 'os': 'Ubuntu', + 'os_version': '12.04-64 Minimal for VSI', + 'notes': 'notes', + 'price_rate': 0, + 'tags': ['production'], + 'private_cpu': {}, + 'private_ip': '10.45.19.37', + 'private_only': {}, + 'ptr': 'test.softlayer.com.', + 'public_ip': '172.16.240.2', + 'state': 'RUNNING', + 'status': 'ACTIVE', + 'users': [{'software': 'Ubuntu', + 'password': 'pass', + 'username': 'user'}], + 'vlans': [{'type': 'PUBLIC', + 'number': 23, + 'id': 1}], + 'owner': None}) + def test_detail_vs(self): result = self.run_command(['vs', 'detail', '100', '--passwords', '--price']) From d091ed550e74fe0692233e1e1a75f7e4f640af29 Mon Sep 17 00:00:00 2001 From: Erick Sapp Date: Thu, 31 May 2018 14:40:11 -0500 Subject: [PATCH 2/5] Add unit test for CLI/virt/cancel.py --- tests/CLI/modules/vs_tests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/CLI/modules/vs_tests.py b/tests/CLI/modules/vs_tests.py index 37e6922d6..06fb83292 100644 --- a/tests/CLI/modules/vs_tests.py +++ b/tests/CLI/modules/vs_tests.py @@ -849,3 +849,17 @@ def test_reload_no_confirm(self, confirm_mock): result = self.run_command(['vs', 'reload', '--postinstall', '100', '--key', '100', '--image', '100', '100']) self.assertEqual(result.exit_code, 2) + + @mock.patch('SoftLayer.CLI.formatting.no_going_back') + def test_cancel(self, confirm_mock): + confirm_mock.return_value = True + + result = self.run_command(['vs', 'cancel', '100']) + self.assert_no_fail(result) + + @mock.patch('SoftLayer.CLI.formatting.no_going_back') + def test_cancel_no_confirm(self, confirm_mock): + confirm_mock.return_value = False + + result = self.run_command(['vs', 'cancel', '100']) + self.assertEqual(result.exit_code, 2) From a4ab0f20435622c9187d2214d1ee3160de6e5337 Mon Sep 17 00:00:00 2001 From: Erick Sapp Date: Thu, 31 May 2018 15:58:15 -0500 Subject: [PATCH 3/5] Added new unit tests for CLI/virt/create.py --- tests/CLI/modules/vs_tests.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/CLI/modules/vs_tests.py b/tests/CLI/modules/vs_tests.py index 06fb83292..ac3fe60e7 100644 --- a/tests/CLI/modules/vs_tests.py +++ b/tests/CLI/modules/vs_tests.py @@ -531,6 +531,25 @@ def test_create_like_flavor(self, confirm_mock): self.assert_called_with('SoftLayer_Virtual_Guest', 'createObject', args=args) + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_vs_test(self, confirm_mock): + confirm_mock.return_value = True + + result = self.run_command(['vs', 'create', '--test', '--hostname', 'TEST', + '--domain', 'TESTING', '--cpu', '1', + '--memory', '2048MB', '--datacenter', + 'TEST00', '--os', 'UBUNTU_LATEST']) + + self.assertEqual(result.exit_code, -1) + + def test_create_vs_bad_memory(self): + result = self.run_command(['vs', 'create', '--hostname', 'TEST', + '--domain', 'TESTING', '--cpu', '1', + '--memory', '2034MB', '--flavor', + 'UBUNTU', '--datacenter', 'TEST00']) + + self.assertEqual(result.exit_code, 2) + @mock.patch('SoftLayer.CLI.formatting.confirm') def test_dns_sync_both(self, confirm_mock): confirm_mock.return_value = True From e25a0782cf64bf667311c9398a8bab8ce450d816 Mon Sep 17 00:00:00 2001 From: Erick Sapp Date: Sun, 10 Jun 2018 14:02:20 -0500 Subject: [PATCH 4/5] Added new unit tests for VSI provisioning in virt/create.py. --- tests/CLI/modules/vs_tests.py | 110 +++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 2 deletions(-) diff --git a/tests/CLI/modules/vs_tests.py b/tests/CLI/modules/vs_tests.py index ac3fe60e7..9ab33124d 100644 --- a/tests/CLI/modules/vs_tests.py +++ b/tests/CLI/modules/vs_tests.py @@ -305,6 +305,7 @@ def test_create_options(self): @mock.patch('SoftLayer.CLI.formatting.confirm') def test_create(self, confirm_mock): confirm_mock.return_value = True + result = self.run_command(['vs', 'create', '--cpu=2', '--domain=example.com', @@ -333,8 +334,53 @@ def test_create(self, confirm_mock): 'operatingSystemReferenceCode': 'UBUNTU_LATEST', 'networkComponents': [{'maxSpeed': '100'}], 'supplementalCreateObjectOptions': {'bootMode': None}},) - self.assert_called_with('SoftLayer_Virtual_Guest', 'createObject', - args=args) + self.assert_called_with('SoftLayer_Virtual_Guest', 'createObject', args=args) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_with_wait_ready(self, confirm_mock): + mock = self.set_mock('SoftLayer_Virtual_Guest', 'getObject') + mock.return_value = { + "provisionDate": "2018-06-10T12:00:00-05:00", + "id": 100 + } + confirm_mock.return_value = True + + result = self.run_command(['vs', 'create', + '--cpu=2', + '--domain=example.com', + '--hostname=host', + '--os=UBUNTU_LATEST', + '--memory=1', + '--network=100', + '--billing=hourly', + '--datacenter=dal05', + '--wait=1']) + + self.assert_no_fail(result) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_with_wait_not_ready(self, confirm_mock): + mock = self.set_mock('SoftLayer_Virtual_Guest', 'getObject') + mock.return_value = { + "ready": False, + "guid": "1a2b3c-1701", + "id": 100, + "created": "2018-06-10 12:00:00" + } + confirm_mock.return_value = True + + result = self.run_command(['vs', 'create', + '--cpu=2', + '--domain=example.com', + '--hostname=host', + '--os=UBUNTU_LATEST', + '--memory=1', + '--network=100', + '--billing=hourly', + '--datacenter=dal05', + '--wait=10']) + + self.assertEqual(result.exit_code, 1) @mock.patch('SoftLayer.CLI.formatting.confirm') def test_create_with_integer_image_id(self, confirm_mock): @@ -405,6 +451,66 @@ def test_create_with_flavor(self, confirm_mock): self.assert_called_with('SoftLayer_Virtual_Guest', 'createObject', args=args) + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_with_flavor_and_memory(self, confirm_mock): + confirm_mock.return_value = True + + result = self.run_command(['vs', 'create', + '--domain=example.com', + '--hostname=host', + '--os=UBUNTU_LATEST', + '--network=100', + '--datacenter=TEST00', + '--flavor=BL_1X2X25', + '--memory=2048MB']) + + self.assertEqual(result.exit_code, 2) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_with_dedicated_and_flavor(self, confirm_mock): + confirm_mock.return_value = True + + result = self.run_command(['vs', 'create', + '--domain=example.com', + '--hostname=host', + '--os=UBUNTU_LATEST', + '--network=100', + '--datacenter=TEST00', + '--dedicated', + '--flavor=BL_1X2X25']) + + self.assertEqual(result.exit_code, 2) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_with_hostid_and_flavor(self, confirm_mock): + confirm_mock.return_value = True + + result = self.run_command(['vs', 'create', + '--domain=example.com', + '--hostname=host', + '--os=UBUNTU_LATEST', + '--network=100', + '--datacenter=dal05', + '--host-id=100', + '--flavor=BL_1X2X25']) + + self.assertEqual(result.exit_code, 2) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_with_flavor_and_cpu(self, confirm_mock): + confirm_mock.return_value = True + + result = self.run_command(['vs', 'create', + '--domain=example.com', + '--hostname=host', + '--os=UBUNTU_LATEST', + '--network=100', + '--datacenter=TEST00', + '--flavor=BL_1X2X25', + '--cpu=2']) + + self.assertEqual(result.exit_code, 2) + @mock.patch('SoftLayer.CLI.formatting.confirm') def test_create_with_host_id(self, confirm_mock): confirm_mock.return_value = True From d0bb1da831ec64d1c4138649c933731c6729711f Mon Sep 17 00:00:00 2001 From: Erick Sapp Date: Sun, 10 Jun 2018 14:17:27 -0500 Subject: [PATCH 5/5] Fixed a line that was unintentionally changed. --- tests/CLI/modules/vs_tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/CLI/modules/vs_tests.py b/tests/CLI/modules/vs_tests.py index 9ab33124d..c7ce60be8 100644 --- a/tests/CLI/modules/vs_tests.py +++ b/tests/CLI/modules/vs_tests.py @@ -334,7 +334,8 @@ def test_create(self, confirm_mock): 'operatingSystemReferenceCode': 'UBUNTU_LATEST', 'networkComponents': [{'maxSpeed': '100'}], 'supplementalCreateObjectOptions': {'bootMode': None}},) - self.assert_called_with('SoftLayer_Virtual_Guest', 'createObject', args=args) + self.assert_called_with('SoftLayer_Virtual_Guest', 'createObject', + args=args) @mock.patch('SoftLayer.CLI.formatting.confirm') def test_create_with_wait_ready(self, confirm_mock):