Skip to content

Commit cdca89e

Browse files
authored
Merge pull request #795 from QualiSystems/release/v1.3.1
Release/v1.3.1
2 parents 3173974 + c52edc8 commit cdca89e

32 files changed

Lines changed: 405 additions & 37 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,7 @@ deployment
7777

7878
#Misc
7979
.imdone
80-
develop.cmd
80+
develop.cmd
81+
*.zip
82+
debug.xml
83+
debug_info.txt

.travis.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
after_success: coveralls
2+
env:
3+
- CLOUD_SHELL_SHELL_CORE=1
4+
- CLOUD_SHELL_SHELL_CORE=2
5+
install:
6+
- pip install -r external_requirements.txt
7+
- pip install -r test_requirements.txt
8+
- pip install "cloudshell-core>=2.0.0,<2.1.0" --extra-index-url https://testpypi.python.org/simple
9+
- chmod 777 ./cloudshell_shell_core_install.sh
10+
- ./cloudshell_shell_core_install.sh
11+
- pip install "cloudshell-automation-api>=7.1.0.0,<7.2.0.0" --extra-index-url https://testpypi.python.org/simple
112
language: python
2-
python:
3-
- "2.7"
4-
5-
install:
6-
- pip install -r external_requirements.txt
7-
- pip install -r test_requirements.txt
8-
- pip install "cloudshell-core>=2.0.0,<2.1.0" --extra-index-url https://testpypi.python.org/simple
9-
- pip install "cloudshell-shell-core>=2.0.0,<2.1.0" --extra-index-url https://testpypi.python.org/simple
10-
- pip install "cloudshell-automation-api>=7.1.0.0,<7.2.0.0" --extra-index-url https://testpypi.python.org/simple
11-
12-
script:
13-
- pushd package
14-
- python setup.py develop
15-
- popd
16-
- python runtests.py --with-coverage --cover-package=package --exclude-dir=integration
17-
18-
after_success:
19-
coveralls
20-
21-
notifications:
22-
webhools: https://qualisystems.getbadges.io/api/app/webhook/63350e33-4119-49c3-8127-075aaa022926
13+
notifications:
14+
webhools: "https://qualisystems.getbadges.io/api/app/webhook/63350e33-4119-49c3-8127-075aaa022926"
15+
python:
16+
- "2.7"
17+
script:
18+
- pushd package
19+
- python setup.py develop
20+
- popd
21+
- chmod 777 ./run_static_or_vcenter_tests.sh
22+
- ./run_static_or_vcenter_tests.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/QualiSystems/vCenterShell.svg?branch=master)](https://travis-ci.org/QualiSystems/vCenterShell) [![Coverage Status](https://coveralls.io/repos/QualiSystems/vCenterShell/badge.svg?branch=develop&service=github)](https://coveralls.io/github/QualiSystems/vCenterShell?branch=develop) [![Code Climate](https://codeclimate.com/github/QualiSystems/vCenterShell/badges/gpa.svg)](https://codeclimate.com/github/QualiSystems/vCenterShell)
1+
[![PyPI](https://img.shields.io/pypi/v/cloudshell-cp-vcenter.svg?maxAge=2592000)](https://pypi.python.org/pypi/cloudshell-cp-vcenter/) [![Build Status](https://travis-ci.org/QualiSystems/vCenterShell.svg?branch=master)](https://travis-ci.org/QualiSystems/vCenterShell) [![Coverage Status](https://coveralls.io/repos/QualiSystems/vCenterShell/badge.svg?branch=develop&service=github)](https://coveralls.io/github/QualiSystems/vCenterShell?branch=develop) [![Code Climate](https://codeclimate.com/github/QualiSystems/vCenterShell/badges/gpa.svg)](https://codeclimate.com/github/QualiSystems/vCenterShell)
22
[![Dependency Status](https://dependencyci.com/github/QualiSystems/vCenterShell/badge)](https://dependencyci.com/github/QualiSystems/vCenterShell)
33
[ ![Foo](https://qualisystems.getbadges.io/shield/company/qualisystems) ](https://getbadges.io) [![Stories in Ready](https://badge.waffle.io/QualiSystems/vCenterShell.svg?label=ready&title=Ready)](http://waffle.io/QualiSystems/vCenterShell) [![Join the chat at https://gitter.im/QualiSystems/vCenterShell](https://badges.gitter.im/QualiSystems/vCenterShell.svg)](https://gitter.im/QualiSystems/vCenterShell?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Analytics](https://ga-beacon.appspot.com/UA-72194260-1/QualiSystems/vCenterShell)](https://github.com/QualiSystems/vCenterShell/)
44

cloudshell_shell_core_install.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
if [ "${CLOUD_SHELL_SHELL_CORE}" -eq 1 ]
3+
then
4+
pip install "cloudshell-shell-core>=2.0.0,<2.1.0" --extra-index-url https://testpypi.python.org/simple
5+
else
6+
pip install "cloudshell-shell-core>=2.4.0,<2.5.0" --extra-index-url https://testpypi.python.org/simple
7+
fi

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import time
2-
from datetime import date
2+
from datetime import datetime, date
33
import jsonpickle
44
from cloudshell.cp.vcenter.models.OrchestrationSaveResult import OrchestrationSaveResult
55
from cloudshell.cp.vcenter.models.OrchestrationSavedArtifactsInfo import OrchestrationSavedArtifactsInfo
@@ -324,7 +324,8 @@ def refresh_ip(self, context, cancellation_context, ports):
324324
self.refresh_ip_command.refresh_ip,
325325
resource_details.vm_uuid,
326326
resource_details.fullname,
327-
cancellation_context)
327+
cancellation_context,
328+
context.remote_endpoints[0].app_context.app_request_json)
328329
return set_command_result(result=res, unpicklable=False)
329330

330331
# remote command
@@ -454,7 +455,7 @@ def orchestration_save(self, context, mode="shallow", custom_params=None):
454455
:rtype: SavedResults
455456
"""
456457
resource_details = self._parse_remote_model(context)
457-
created_date = date.today()
458+
created_date = datetime.now()
458459
snapshot_name = created_date.strftime('%y_%m_%d %H_%M_%S_%f')
459460
created_snapshot_path = self.save_snapshot(context=context, snapshot_name=snapshot_name)
460461

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/cp/vcenter/commands/save_snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ def _verify_snapshot_uniquness(snapshot_path_to_be_created, vm):
6060
def _get_snapshot_name_to_be_created(snapshot_name, vm):
6161
current_snapshot_name = SnapshotRetriever.get_current_snapshot_name(vm)
6262
if not current_snapshot_name:
63-
return ''
63+
return snapshot_name
6464
return SnapshotRetriever.combine(current_snapshot_name, snapshot_name)

package/cloudshell/tests/test_commands/test_command_orchestrator.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest import TestCase
2+
from freezegun import freeze_time
23

34
import jsonpickle
45
from cloudshell.api.cloudshell_api import ResourceInfo
@@ -36,6 +37,8 @@ def setUp(self):
3637
remote_resource.uuid = 'this is full uuis of the remote resource'
3738
self.connection_details = Mock()
3839
self.context.resource = self.resource
40+
self.context.resource.app_context = Mock()
41+
self.context.remote_endpoints = Mock()
3942
self.context.remote_endpoints = [self.resource]
4043
self.command_orchestrator = CommandOrchestrator()
4144
self.command_orchestrator.command_wrapper.execute_command_with_connection = Mock(return_value=True)
@@ -131,7 +134,7 @@ def test_get_snapshots(self):
131134
self.command_orchestrator.get_snapshots(self.context)
132135
self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called)
133136

134-
def test_orchestration_save(self):
137+
def test_orchestration_save_double_quotes_in_snapshot_name_should_be_stripped(self):
135138
# Arrange
136139
with patch(SAVE_SNAPSHOT) as save_snapshot_mock:
137140
save_snapshot_mock.return_value = '"new_snapshot"'
@@ -159,6 +162,30 @@ def test_orchestration_save(self):
159162
self.assertEqual(saved_result_dict['saved_artifacts_info']['resource_name'], 'vcenter')
160163
self.assertIsNotNone(saved_result_dict['saved_artifacts_info']['created_date'])
161164

165+
@freeze_time("1984-12-31 11:12:13.4567")
166+
def test_orchestration_save_snapshot_name_should_contain_full_datetime(self):
167+
# Arrange
168+
with patch(SAVE_SNAPSHOT) as save_snapshot_mock:
169+
save_snapshot_mock.return_value = '"new_snapshot"'
170+
171+
remote_command_context = create_autospec(ResourceRemoteCommandContext)
172+
remote_command_context.resource = create_autospec(ResourceContextDetails)
173+
remote_command_context.resource.fullname = 'vcenter'
174+
endpoint = create_autospec(ResourceContextDetails)
175+
endpoint.fullname = 'vm_111'
176+
endpoint.app_context = create_autospec(AppContext)
177+
endpoint.app_context.deployed_app_json = '{"vmdetails": {"uid": "vm_uuid1"}}'
178+
remote_command_context.remote_endpoints = [endpoint]
179+
180+
# Act
181+
CommandOrchestrator().orchestration_save(context=remote_command_context,
182+
mode='shallow',
183+
custom_params=None)
184+
185+
# Assert
186+
args, kwargs = save_snapshot_mock.call_args
187+
self.assertEqual(kwargs['snapshot_name'], "84_12_31 11_12_13_456700")
188+
162189
def test_orchestration_restore(self):
163190
# Arrange
164191
with patch(RESTORE_SNAPSHOT) as mock_restore_snapshot:

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)

run_static_or_vcenter_tests.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
if [ "${CLOUD_SHELL_SHELL_CORE}" -eq 1 ]
3+
then
4+
echo "Running vCenter Tests"
5+
python runtests.py --with-coverage --cover-package=package --exclude-dir=integration
6+
else
7+
echo "Running static VM Tests"
8+
python runtestsStaticVM.py --with-coverage --cover-package=package --exclude-dir=integration
9+
fi

0 commit comments

Comments
 (0)