Skip to content

Commit 555711e

Browse files
authored
Merge pull request #779 from QualiSystems/feature/fix_failing_tests
Feature/fix failing tests
2 parents be573a9 + e8829a4 commit 555711e

4 files changed

Lines changed: 26 additions & 24 deletions

File tree

package/cloudshell/cp/vcenter/commands/command_orchestrator.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,21 +318,16 @@ def refresh_ip(self, context, cancellation_context, ports):
318318
:param cancellation_context:
319319
:param list[string] ports: the ports of the connection between the remote resource and the local resource, NOT IN USE!!!
320320
"""
321-
self.do_not_run_on_static_vm(context)
322-
323321
resource_details = self._parse_remote_model(context)
324322
# execute command
325323
res = self.command_wrapper.execute_command_with_connection(context,
326324
self.refresh_ip_command.refresh_ip,
327325
resource_details.vm_uuid,
328326
resource_details.fullname,
329-
cancellation_context)
327+
cancellation_context,
328+
context.remote_endpoints[0].app_context.app_request_json)
330329
return set_command_result(result=res, unpicklable=False)
331330

332-
def do_not_run_on_static_vm(self, context):
333-
if context.resource.app_context.deployed_app_json == '' or context.resource.app_context.deployed_app_json == None:
334-
raise ValueError('This command cannot be executed on a Static VM.')
335-
336331
# remote command
337332
def power_off(self, context, ports):
338333
"""

package/cloudshell/cp/vcenter/commands/refresh_ip.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ def __init__(self, pyvmomi_service, resource_model_parser, ip_manager):
1515
self.resource_model_parser = resource_model_parser
1616
self.ip_manager = ip_manager
1717

18-
def refresh_ip(self, si, logger, session, vcenter_data_model, vm_uuid, resource_name, cancellation_context):
18+
def _do_not_run_on_static_vm(self, app_request_json):
19+
if app_request_json == '' or app_request_json is None:
20+
raise ValueError('This command cannot be executed on a Static VM.')
21+
22+
def refresh_ip(self, si, logger, session, vcenter_data_model, vm_uuid, resource_name, cancellation_context,app_request_json):
1923
"""
2024
Refreshes IP address of virtual machine and updates Address property on the resource
2125
@@ -27,7 +31,10 @@ def refresh_ip(self, si, logger, session, vcenter_data_model, vm_uuid, resource_
2731
:param VMwarevCenterResourceModel vcenter_data_model: the vcenter data model attributes
2832
:param cancellation_context:
2933
"""
30-
default_network = VMLocation.combine([vcenter_data_model.default_datacenter, vcenter_data_model.holding_network])
34+
self._do_not_run_on_static_vm(app_request_json=app_request_json)
35+
36+
default_network = VMLocation.combine(
37+
[vcenter_data_model.default_datacenter, vcenter_data_model.holding_network])
3138

3239
resource = session.GetResourceDetails(resource_name)
3340

@@ -79,5 +86,3 @@ def _get_custom_param(resource, custom_param_name):
7986
if custom_param_values:
8087
return custom_param_values[0]
8188
return None
82-
83-

package/cloudshell/tests/test_commands/test_command_orchestrator.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def setUp(self):
3838
self.connection_details = Mock()
3939
self.context.resource = self.resource
4040
self.context.resource.app_context = Mock()
41-
self.context.resource.app_context.deployed_app_json = "some json"
41+
self.context.remote_endpoints = Mock()
4242
self.context.remote_endpoints = [self.resource]
4343
self.command_orchestrator = CommandOrchestrator()
4444
self.command_orchestrator.command_wrapper.execute_command_with_connection = Mock(return_value=True)
@@ -118,13 +118,6 @@ def test_refresh_ip(self):
118118
# assert
119119
self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called)
120120

121-
def test_refresh_ip_should_fail_static_vm(self):
122-
# act
123-
self.context.resource.app_context.deployed_app_json = None
124-
cancellation_context = object()
125-
# assert
126-
self.assertRaises(ValueError, self.command_orchestrator.refresh_ip,self.context, cancellation_context, self.ports)
127-
128121
def test_get_uuid(self):
129122
self.command_orchestrator.get_vm_uuid_by_name(self.context, 'Name')
130123
self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called)

package/cloudshell/tests/test_commands/test_refresh_ip.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class TestRefreshIpCommand(TestCase):
11-
1211
def test_refresh_ip(self):
1312
nic1 = Mock()
1413
nic1.network = 'A Network'
@@ -53,11 +52,12 @@ def test_refresh_ip(self):
5352
# Act
5453
refresh_ip_command.refresh_ip(si=si,
5554
session=session,
56-
vcenter_data_model= center_resource_model,
55+
vcenter_data_model=center_resource_model,
5756
vm_uuid='machine1',
5857
resource_name='default_network',
5958
cancellation_context=cancellation_context,
60-
logger=Mock())
59+
logger=Mock(),
60+
app_request_json=Mock())
6161

6262
# Assert
6363
self.assertTrue(session.UpdateResourceAddress.called_with('machine1', '192.168.1.1'))
@@ -119,7 +119,8 @@ def test_refresh_ip_choose_ipv4(self):
119119
vm_uuid='machine1',
120120
resource_name='default_network',
121121
cancellation_context=cancellation_context,
122-
logger=Mock())
122+
logger=Mock(),
123+
app_request_json=Mock())
123124

124125
# Assert
125126
self.assertTrue(session.UpdateResourceAddress.called_with('machine1', '192.168.1.1'))
@@ -173,7 +174,15 @@ def test_refresh_ip_choose_ip_by_regex(self):
173174
vm_uuid='machine1',
174175
resource_name='default_network',
175176
cancellation_context=cancellation_context,
176-
logger=Mock())
177+
logger=Mock(),
178+
app_request_json=Mock())
177179

178180
# Assert
179181
self.assertTrue(session.UpdateResourceAddress.called_with('machine1', '192.168.1.1'))
182+
183+
def test_refresh_ip_should_fail_static_vm(self):
184+
# Act
185+
refresh_ip_command = RefreshIpCommand(Mock(), Mock(), Mock())
186+
# assert
187+
self.assertRaises(ValueError, refresh_ip_command.refresh_ip, Mock(), Mock(), Mock(), Mock(), Mock(), Mock(),
188+
Mock(), None)

0 commit comments

Comments
 (0)