diff --git a/tests/CLI/modules/vs_tests.py b/tests/CLI/modules/vs_tests.py index 0b4883902..c7ce60be8 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']) @@ -257,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', @@ -288,6 +337,52 @@ def test_create(self, confirm_mock): 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): confirm_mock.return_value = True @@ -357,6 +452,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 @@ -483,6 +638,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 @@ -801,3 +975,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)