def test_should_delete_bulk_fc_networks(self): networkUris = [ "/rest/fc-networks/e2f0031b-52bd-4223-9ac1-d91cb519d548", "/rest/fc-networks/f2f0031b-52bd-4223-9ac1-d91cb519d549", "/rest/fc-networks/02f0031b-52bd-4223-9ac1-d91cb519d54a" ] PARAMS_FOR_BULK_DELETED = dict( config='config.json', state='absent', data=dict(networkUris=[ "/rest/fc-networks/e2f0031b-52bd-4223-9ac1-d91cb519d548", "/rest/fc-networks/f2f0031b-52bd-4223-9ac1-d91cb519d549", "/rest/fc-networks/02f0031b-52bd-4223-9ac1-d91cb519d54a" ]) ) self.resource.delete_bulk.return_value = None self.mock_ansible_module.params = PARAMS_FOR_BULK_DELETED FcNetworkModule().run() self.resource.delete_bulk.assert_called_once_with({'networkUris': networkUris}) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=FcNetworkModule.BULK_MSG_DELETED, ansible_facts=dict(fc_network_bulk_delete=None))
def test_not_update_when_only_bandwidth_has_modified_attributes(self): DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH = { 'name': 'New FC Network 2', 'connectionTemplateUri': '/rest/', 'bandwidth': { 'maximumBandwidth': 20, 'typicalBandwidth': 10 }, 'fabricType': 'DirectAttach' } PARAMS_WITH_CONNECTIONTEMPLATE = dict( config='config.json', state='present', data=dict(name="New FC Network 2", connectionTemplateUri='/rest/', fabricType='DirectAttach', bandwidth=dict(maximumBandwidth=20, typicalBandwidth=10))) self.resource.data = DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH self.mock_ansible_module.check_mode = False self.mock_ansible_module.params = PARAMS_WITH_CONNECTIONTEMPLATE self.resource.update.return_value = self.resource obj = mock.Mock() get_by_uri_data = DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH.copy() get_by_uri_data['bandwidth']['maximumBandwidth'] = 21 obj.data = get_by_uri_data self.mock_ov_client.connection_templates.get_by_uri.return_value = obj FcNetworkModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=FcNetworkModule.MSG_UPDATED, ansible_facts=dict( fc_network=DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH))
def test_with_check_mode_update_scopes_when_different(self): params_to_scope = PARAMS_FOR_PRESENT.copy() params_to_scope['data']['scopeUris'] = ['test'] self.mock_ansible_module.params = params_to_scope resource_data = CHECK_MODE_DEFAULT_FC_NETWORK_TEMPLATE.copy() resource_data['scopeUris'] = ['fake'] self.resource.data = resource_data patch_return = resource_data.copy() patch_return['scopeUris'] = ['test'] patch_return_obj = self.resource.copy() patch_return_obj.data = patch_return self.resource.patch.return_value = patch_return_obj self.mock_ansible_module.check_mode = True FcNetworkModule().run() del(patch_return['scopeUris']) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(fc_network=patch_return), msg=FcNetworkModule.MSG_UPDATED )
def test_not_update_when_bandwidth_has_no_connectiontemplateuri_attribute( self): DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH = { 'name': 'New FC Network 2', 'bandwidth': { 'maximumBandwidth': 20, 'typicalBandwidth': 10 }, 'fabricType': 'DirectAttach', } PARAMS_WITH_NO_CONNECTIONTEMPLATE = dict( config='config.json', state='present', data=dict(name=DEFAULT_FC_NETWORK_TEMPLATE['name'], fabricType='DirectAttach', bandwidth=dict(maximumBandwidth=20, typicalBandwidth=10))) self.resource.data = DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH self.mock_ansible_module.check_mode = False self.mock_ansible_module.params = PARAMS_WITH_NO_CONNECTIONTEMPLATE self.resource.update.return_value = self.resource obj = mock.Mock() obj.data = self.resource self.mock_ov_client.connection_templates.get_by_uri.return_value = obj FcNetworkModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=FcNetworkModule.MSG_ALREADY_PRESENT, ansible_facts=dict( fc_network=DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH))
def test_update_when_only_bandwidth_has_modified_attributes(self): DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH = { 'name': 'New FC Network 2', 'connectionTemplateUri': '/rest/', 'bandwidth': { 'maximumBandwidth': 20, 'typicalBandwidth': 10 }, 'autoLoginRedistribution': 'True', 'fabricType': 'FabricAttach', } self.resource.data = DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH self.mock_ansible_module.check_mode = False self.mock_ansible_module.params = PARAMS_WITH_BANDWIDTH self.resource.update.return_value = self.resource obj = mock.Mock() obj.data = {"uri": "uri"} self.mock_ov_client.connection_templates.get_by_uri.return_value = obj FcNetworkModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=FcNetworkModule.MSG_UPDATED, ansible_facts=dict( fc_network=DEFAULT_FC_NETWORK_TEMPLATE_WITH_BANDWIDTH))
def test_with_check_mode_should_remove_fc_network(self): self.resource.data = [DEFAULT_FC_NETWORK_TEMPLATE] self.mock_ansible_module.params = PARAMS_FOR_ABSENT self.mock_ansible_module.check_mode = True FcNetworkModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=FcNetworkModule.MSG_DELETED)
def test_with_check_mode_should_do_nothing_when_fc_network_not_exist(self): self.resource.get_by_name.return_value = [] self.mock_ansible_module.params = PARAMS_FOR_ABSENT self.mock_ansible_module.check_mode = True FcNetworkModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=FcNetworkModule.MSG_ALREADY_ABSENT)
def test_should_not_update_when_data_is_equals(self): self.resource.data = DEFAULT_FC_NETWORK_TEMPLATE self.mock_ansible_module.params = PARAMS_FOR_PRESENT self.mock_ansible_module.check_mode = False FcNetworkModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=FcNetworkModule.MSG_ALREADY_PRESENT, ansible_facts=dict(fc_network=DEFAULT_FC_NETWORK_TEMPLATE))
def test_to_check_create_new_fc_network(self): self.resource.get_by_name.return_value = [] self.mock_ansible_module.check_mode = True self.resource.data = CHECK_MODE_DEFAULT_FC_NETWORK_TEMPLATE self.mock_ansible_module.params = PARAMS_FOR_PRESENT FcNetworkModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=FcNetworkModule.MSG_CREATED, ansible_facts=dict(fc_network=CHECK_MODE_DEFAULT_FC_NETWORK_TEMPLATE) )
def test_with_check_mode_update_when_data_has_modified_attributes(self): data_merged = CHECK_MODE_DEFAULT_FC_NETWORK_TEMPLATE.copy() self.resource.data = data_merged self.resource.update.return_value = self.resource self.mock_ansible_module.check_mode = True self.mock_ansible_module.params = CHECK_MODE_PARAMS_WITH_CHANGES FcNetworkModule().run() data_merged['name'] = 'New Name' self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=FcNetworkModule.MSG_UPDATED, ansible_facts=dict(fc_network=data_merged))
def test_should_do_nothing_when_scopes_are_the_same(self): params_to_scope = PARAMS_FOR_PRESENT.copy() params_to_scope['data']['scopeUris'] = ['test'] self.mock_ansible_module.params = params_to_scope self.mock_ansible_module.check_mode = False resource_data = DEFAULT_FC_NETWORK_TEMPLATE.copy() resource_data['scopeUris'] = ['test'] self.resource.data = resource_data FcNetworkModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(fc_network=resource_data), msg=FcNetworkModule.MSG_ALREADY_PRESENT)