diff --git a/CHANGES.md b/CHANGES.md index aa1a1e0..b5e1306 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # Change Log +## v1.3.5 + +Updates: +* Updated test files to work with latest CI updates (@jschoewe) + ## v1.3.4 Updates: diff --git a/pack.yaml b/pack.yaml index 709ec05..43ec9b9 100644 --- a/pack.yaml +++ b/pack.yaml @@ -3,7 +3,7 @@ ref: vsphere name: vsphere description: VMware vSphere stackstorm_version: ">=2.9.0" -version: 1.3.4 +version: 1.3.5 author: Paul Mulvihill email: paul.mulvihill@pulsant.com contributors: diff --git a/requirements-tests.txt b/requirements-tests.txt index 73ef95b..c6dc3ed 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,9 +1 @@ -# these old pins conflict with those in st2 causing CI to fail -# feel free to update if you still want a pack-local cache of the deps -#mock>=1.3.0,<2.0 -#unittest2>=1.1.0,<2.0 -#nose>=1.3.7 -#eventlet==0.25.1 -#requests[security]==2.23.0 -#pytz==2019.1 -pyvmomi==7.0.2 +pyvmomi==8.0.3.0.1 diff --git a/requirements.txt b/requirements.txt index 3000853..c6dc3ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pyvmomi==7.0.2 +pyvmomi==8.0.3.0.1 diff --git a/tests/test_action_vmwarelib_actions.py b/tests/test_action_vmwarelib_actions.py index 14fc0a1..023fc9f 100644 --- a/tests/test_action_vmwarelib_actions.py +++ b/tests/test_action_vmwarelib_actions.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and import mock - -from vmwarelib.actions import BaseAction from vsphere_base_action_test_case import VsphereBaseActionTestCase from get_objects_with_tag import GetObjectsWithTag @@ -28,13 +26,23 @@ class BaseActionTestCase(VsphereBaseActionTestCase): # action_cls = BaseAction action_cls = GetObjectsWithTag - def test_init(self): - action = self.get_action_instance(self._new_config) - self.assertIsInstance(action, BaseAction) + def test_init_config_new(self): + action = self.get_action_instance(self.new_config) + self.assertIsInstance(action, self.action_cls) + + def test_init_config_blank(self): + self.assertRaises(ValueError, self.action_cls, self.blank_config) + + def test_init_config_old(self): + self.assertRaises(ValueError, self.action_cls, self.old_config) + + def test_init_config_old_partial(self): + self.assertRaises(ValueError, self.action_cls, self.old_config_partial) - def test_init_blank_config(self): - with self.assertRaises(ValueError): - self.get_action_instance(self._blank_config) + def test_init_config_new_partial(self): + action = self.get_action_instance(self.new_config_partial) + self.assertRaises(KeyError, action.establish_connection, + vsphere="default") def test_get_connection_info(self): action = self.get_action_instance(self._new_config) diff --git a/tests/test_action_vmwarelib_tagging.py b/tests/test_action_vmwarelib_tagging.py index 0194f66..2ca270c 100644 --- a/tests/test_action_vmwarelib_tagging.py +++ b/tests/test_action_vmwarelib_tagging.py @@ -259,7 +259,7 @@ def test_category_list(self, mock_get): # assert mock_get.assert_called_with("/rest/com/vmware/cis/tagging/category") - self.assertEquals(result, expected) + self.assertEqual(result, expected) @mock.patch("vmwarelib.tagging.VmwareTagging.get") def test_category_get(self, mock_get): @@ -274,7 +274,7 @@ def test_category_get(self, mock_get): # assert mock_get.assert_called_with("/rest/com/vmware/cis/tagging/category/id:1234") - self.assertEquals(result, expected) + self.assertEqual(result, expected) @mock.patch("vmwarelib.tagging.VmwareTagging.delete") def test_category_delete(self, mock_delete): @@ -289,7 +289,7 @@ def test_category_delete(self, mock_delete): # assert mock_delete.assert_called_with("/rest/com/vmware/cis/tagging/category/id:1234") - self.assertEquals(result, expected) + self.assertEqual(result, expected) @mock.patch("vmwarelib.tagging.VmwareTagging.category_get") @mock.patch("vmwarelib.tagging.VmwareTagging.category_list") @@ -307,7 +307,7 @@ def test_category_find_by_name(self, mock_category_list, mock_category_get): result = action.category_find_by_name("b") # assert - self.assertEquals(result, {"name": "b", "value": "xx"}) + self.assertEqual(result, {"name": "b", "value": "xx"}) @mock.patch("vmwarelib.tagging.VmwareTagging.category_get") @mock.patch("vmwarelib.tagging.VmwareTagging.category_list") @@ -325,15 +325,15 @@ def test_category_find_by_name_not_found(self, mock_category_list, mock_category result = action.category_find_by_name("abc123") # assert - self.assertEquals(result, None) + self.assertEqual(result, None) def test_category_create_spec(self): action = self.create_class_object() create_spec = action.category_create_spec() - self.assertEquals(create_spec, {"name": "", - "description": "", - "cardinality": "SINGLE", - "associable_types": []}) + self.assertEqual(create_spec, {"name": "", + "description": "", + "cardinality": "SINGLE", + "associable_types": []}) @mock.patch("vmwarelib.tagging.VmwareTagging.post") def test_category_create_all_params(self, mock_post): @@ -360,7 +360,7 @@ def test_category_create_all_params(self, mock_post): # assert mock_post.assert_called_with("/rest/com/vmware/cis/tagging/category", payload={"create_spec": expected_create_spec}) - self.assertEquals(result, "expected result") + self.assertEqual(result, "expected result") @mock.patch("vmwarelib.tagging.VmwareTagging.post") def test_category_create_no_params(self, mock_post): @@ -382,7 +382,7 @@ def test_category_create_no_params(self, mock_post): # assert mock_post.assert_called_with("/rest/com/vmware/cis/tagging/category", payload={"create_spec": expected_create_spec}) - self.assertEquals(result, "expected result") + self.assertEqual(result, "expected result") @mock.patch("vmwarelib.tagging.VmwareTagging.category_find_by_name") def test_category_get_or_create_get(self, mock_category_find_by_name): @@ -397,7 +397,7 @@ def test_category_get_or_create_get(self, mock_category_find_by_name): # assert mock_category_find_by_name.assert_called_with("name") - self.assertEquals(result, "fake category") + self.assertEqual(result, "fake category") @mock.patch("vmwarelib.tagging.VmwareTagging.category_get") @mock.patch("vmwarelib.tagging.VmwareTagging.category_create") @@ -426,7 +426,7 @@ def test_category_get_or_create_create_all_params(self, mock_category_find_by_na mock_category_create.assert_called_with(test_name, test_description, test_cardinality, test_associable_types) mock_category_get.assert_called_with("123") - self.assertEquals(result, "fake category") + self.assertEqual(result, "fake category") @mock.patch("vmwarelib.tagging.VmwareTagging.category_get") @mock.patch("vmwarelib.tagging.VmwareTagging.category_create") @@ -450,7 +450,7 @@ def test_category_get_or_create_create_no_params(self, mock_category_find_by_nam mock_category_find_by_name.assert_called_with(test_name) mock_category_create.assert_called_with(test_name, None, None, None) mock_category_get.assert_called_with("123") - self.assertEquals(result, "fake category") + self.assertEqual(result, "fake category") ############################################################################ @@ -470,7 +470,7 @@ def test_tag_list_category(self, mock_post): # assert mock_post.assert_called_with("/rest/com/vmware/cis/tagging/tag/id:1234", params={"~action": "list-tags-for-category"}) - self.assertEquals(result, expected) + self.assertEqual(result, expected) @mock.patch("vmwarelib.tagging.VmwareTagging.get") def test_tag_list_no_category(self, mock_get): @@ -484,7 +484,7 @@ def test_tag_list_no_category(self, mock_get): # assert mock_get.assert_called_with("/rest/com/vmware/cis/tagging/tag") - self.assertEquals(result, expected) + self.assertEqual(result, expected) @mock.patch("vmwarelib.tagging.VmwareTagging.get") def test_tag_get(self, mock_get): @@ -499,7 +499,7 @@ def test_tag_get(self, mock_get): # assert mock_get.assert_called_with("/rest/com/vmware/cis/tagging/tag/id:1234") - self.assertEquals(result, expected) + self.assertEqual(result, expected) @mock.patch("vmwarelib.tagging.VmwareTagging.delete") def test_tag_delete(self, mock_delete): @@ -514,7 +514,7 @@ def test_tag_delete(self, mock_delete): # assert mock_delete.assert_called_with("/rest/com/vmware/cis/tagging/tag/id:1234") - self.assertEquals(result, expected) + self.assertEqual(result, expected) @mock.patch("vmwarelib.tagging.VmwareTagging.tag_get") @mock.patch("vmwarelib.tagging.VmwareTagging.tag_list") @@ -535,7 +535,7 @@ def test_tag_find_by_name(self, mock_tag_list, mock_tag_get): # assert mock_tag_list.assert_called_with(test_category_id) - self.assertEquals(result, {"name": "b", "value": "xx"}) + self.assertEqual(result, {"name": "b", "value": "xx"}) @mock.patch("vmwarelib.tagging.VmwareTagging.tag_get") @mock.patch("vmwarelib.tagging.VmwareTagging.tag_list") @@ -557,14 +557,14 @@ def test_tag_find_not_found(self, mock_tag_list, mock_tag_get): mock_tag_list.assert_called_with(None) mock_tag_get.assert_has_calls([mock.call("1"), mock.call("2"), mock.call("3")], any_order=True) - self.assertEquals(result, None) + self.assertEqual(result, None) def test_tag_create_spec(self): action = self.create_class_object() create_spec = action.tag_create_spec() - self.assertEquals(create_spec, {"name": "", - "description": "", - "category_id": ""}) + self.assertEqual(create_spec, {"name": "", + "description": "", + "category_id": ""}) @mock.patch("vmwarelib.tagging.VmwareTagging.post") def test_tag_create(self, mock_post): @@ -585,7 +585,7 @@ def test_tag_create(self, mock_post): # assert mock_post.assert_called_with("/rest/com/vmware/cis/tagging/tag", payload={"create_spec": expected_create_spec}) - self.assertEquals(result, "expected result") + self.assertEqual(result, "expected result") @mock.patch("vmwarelib.tagging.VmwareTagging.tag_find_by_name") def test_tag_get_or_create_get(self, mock_tag_find_by_name): @@ -602,7 +602,7 @@ def test_tag_get_or_create_get(self, mock_tag_find_by_name): # assert mock_tag_find_by_name.assert_called_with(test_tag_name, test_category_id) - self.assertEquals(result, "fake tag") + self.assertEqual(result, "fake tag") @mock.patch("vmwarelib.tagging.VmwareTagging.tag_get") @mock.patch("vmwarelib.tagging.VmwareTagging.tag_create") @@ -623,7 +623,7 @@ def test_tag_get_or_create_create(self, mock_tag_find_by_name, mock_tag_find_by_name.assert_called_with(test_tag_name, test_category_id) mock_tag_create.assert_called_with(test_tag_name, test_category_id, None) mock_tag_get.assert_called_with("123") - self.assertEquals(result, "fake tag") + self.assertEqual(result, "fake tag") ############################################################################ @@ -632,14 +632,14 @@ def test_tag_get_or_create_create(self, mock_tag_find_by_name, def test_tag_association_endpoint(self): action = self.create_class_object() result = action.tag_association_endpoint() - self.assertEquals(result, - "/rest/com/vmware/cis/tagging/tag-association") + self.assertEqual(result, + "/rest/com/vmware/cis/tagging/tag-association") def test_tag_association_endpoint_tag_id(self): action = self.create_class_object() result = action.tag_association_endpoint("123") - self.assertEquals(result, - "/rest/com/vmware/cis/tagging/tag-association/id:123") + self.assertEqual(result, + "/rest/com/vmware/cis/tagging/tag-association/id:123") @mock.patch("vmwarelib.tagging.VmwareTagging.post") def test_tag_association_attach(self, mock_post): @@ -651,7 +651,7 @@ def test_tag_association_attach(self, mock_post): params={'~action': "attach"}, payload={"object_id": {"id": "vm-789", "type": "vm"}}) - self.assertEquals(result, "response") + self.assertEqual(result, "response") @mock.patch("vmwarelib.tagging.VmwareTagging.post") def test_tag_association_attach_multiple(self, mock_post): @@ -665,7 +665,7 @@ def test_tag_association_attach_multiple(self, mock_post): payload={"tag_ids": test_tag_ids, "object_id": {"id": "vm-789", "type": "vm"}}) - self.assertEquals(result, "response") + self.assertEqual(result, "response") @mock.patch("vmwarelib.tagging.VmwareTagging.post") def test_tag_association_detach(self, mock_post): @@ -677,7 +677,7 @@ def test_tag_association_detach(self, mock_post): params={'~action': 'detach'}, payload={"object_id": {"id": "vm-789", "type": "vm"}}) - self.assertEquals(result, "response") + self.assertEqual(result, "response") @mock.patch("vmwarelib.tagging.VmwareTagging.post") def test_tag_association_list_attached_tags(self, mock_post): @@ -689,7 +689,7 @@ def test_tag_association_list_attached_tags(self, mock_post): params={'~action': 'list-attached-tags'}, payload={"object_id": {"id": "vm-789", "type": "vm"}}) - self.assertEquals(result, "response") + self.assertEqual(result, "response") @mock.patch("vmwarelib.tagging.VmwareTagging.post") def test_tag_association_list_attached_objects(self, mock_post): @@ -699,7 +699,7 @@ def test_tag_association_list_attached_objects(self, mock_post): mock_post.assert_called_with("/rest/com/vmware/cis/tagging/tag-association/id:123", params={'~action': 'list-attached-objects'}) - self.assertEquals(result, "response") + self.assertEqual(result, "response") @mock.patch("vmwarelib.tagging.VmwareTagging.tag_association_detach") @mock.patch("vmwarelib.tagging.VmwareTagging.tag_get") @@ -714,7 +714,7 @@ def test_tag_association_detach_category(self, mock_tag_association_list_attache {"name": "3", "category_id": "c2"}] results = action.tag_association_detach_category("c2", "vm", "vm-123") - self.assertEquals(results, [{"name": "3", "category_id": "c2"}]) + self.assertEqual(results, [{"name": "3", "category_id": "c2"}]) @mock.patch("vmwarelib.tagging.VmwareTagging.tag_association_detach") @mock.patch("vmwarelib.tagging.VmwareTagging.tag_get") @@ -730,7 +730,7 @@ def test_tag_association_detach_category_no_match(self, {"name": "3", "category_id": "c2"}] results = action.tag_association_detach_category("xyz", "vm", "vm-123") - self.assertEquals(results, []) + self.assertEqual(results, []) @mock.patch("vmwarelib.tagging.VmwareTagging.tag_association_attach") @mock.patch("vmwarelib.tagging.VmwareTagging.tag_association_detach_category") @@ -751,4 +751,4 @@ def test_tag_association_replace(self, mock_tag_get, mock_tag_association_attach.assert_called_with("123", "vm", "vm-789") - self.assertEquals(results, "expected") + self.assertEqual(results, "expected") diff --git a/tests/test_config_schema.py b/tests/test_config_schema.py deleted file mode 100644 index 38e9041..0000000 --- a/tests/test_config_schema.py +++ /dev/null @@ -1,77 +0,0 @@ -import mock -import yaml -import json -import re - -from st2client import shell -from st2client.utils import httpclient -from st2client.models.core import ConfigManager - -from st2tests.http import FakeResponse -from st2tests.pack_resource import BasePackResourceTestCase - - -class ConfigSchemaTestCase(BasePackResourceTestCase): - def setUp(self): - super(ConfigSchemaTestCase, self).setUp() - - self.shell = shell.Shell() - self._content_schema = yaml.safe_load(self.get_fixture_content('config.schema.yaml')) - self._new_config = yaml.safe_load(self.get_fixture_content('cfg_new.yaml')) - - @mock.patch.object(httpclient.HTTPClient, 'get') - @mock.patch.object(ConfigManager, 'update') - @mock.patch('st2client.commands.pack.editor') - @mock.patch('st2client.utils.interactive.prompt') - def test_set_schema(self, mock_prompt, mock_editor, mock_config_update, mock_http_get): - # set dummy HTTP response from the st2api - dummy_api_response = { - 'id': 'dummy1234', - 'pack': 'vsphere', - 'attributes': self._content_schema - } - # with the orjson change, st2client now expects to be able to use - # the response.content attribute, so populate it. - dummy_api_response_content = json.dumps(dummy_api_response) - dummy_api_response_object = FakeResponse(dummy_api_response_content, 200, 'OK') - dummy_api_response_object.content = dummy_api_response_content - mock_http_get.return_value = dummy_api_response_object - - # set dummy paramters - def side_effect_prompt(msg, **kwargs): - if re.compile(r'^ssl_verify').match(msg): - return False - elif re.compile(r'^default.host').match(msg): - return '192.168.0.1' - elif re.compile(r'^default.port').match(msg): - return '443' - elif re.compile(r'^default.user').match(msg): - return 'Admin' - elif re.compile(r'^default.passwd').match(msg): - return 'password' - elif re.compile(r'^taskinfo.tasknum').match(msg): - return '5' - else: - return None - mock_prompt.side_effect = side_effect_prompt - - # skip modification by editor - def side_effect_editor(contents): - return contents - mock_editor.edit.side_effect = side_effect_editor - - # check for the result configuration is expected - def side_effect_config_update(config): - self.assertEqual(config.pack, 'vsphere') - - # check for generated configuration has expected parameters - for k, v in self._new_config.items(): - self.assertEqual(config.values[k], v) - - return config - mock_config_update.side_effect = side_effect_config_update - - # execute pack config command - ret = self.shell.run(['--debug', 'pack', 'config', 'vsphere']) - - self.assertEqual(ret, 0) diff --git a/tests/vsphere_base_action_test_case.py b/tests/vsphere_base_action_test_case.py index 8841bb8..b1d85f7 100644 --- a/tests/vsphere_base_action_test_case.py +++ b/tests/vsphere_base_action_test_case.py @@ -57,25 +57,6 @@ def new_config_partial(self): def old_config_partial(self): return self._old_config_partial - def test_run_config_blank(self): - self.assertRaises(ValueError, self.action_cls, self.blank_config) - - def test_run_config_old(self): - self.assertRaises(ValueError, self.action_cls, self.old_config) - - def test_run_config_new(self): - action = self.get_action_instance(self.new_config) - self.assertIsInstance(action, self.action_cls) - return action - - def test_run_config_old_partial(self): - self.assertRaises(ValueError, self.action_cls, self.old_config_partial) - - def test_run_config_new_partial(self): - action = self.get_action_instance(self.new_config_partial) - self.assertRaises(KeyError, action.establish_connection, - vsphere="default") - def mock_one_vm(self, vm_id): """ Configure a single VM mock. Helps make writing tests against vm actions easier. @@ -86,7 +67,7 @@ def mock_one_vm(self, vm_id): Returns: - (action, mock_vm) """ - action = self.test_run_config_new() + action = self.get_action_instance(self.new_config) action.establish_connection = mock.Mock() action.si_content = mock.Mock() action.si_content.rootFolder = mock.Mock()