def test_should_add_new_storage_system_with_credentials_from_api500(self):
        self.mock_ov_client.api_version = 500
        self.resource.get_by_hostname.return_value = None
        obj = mock.Mock()
        obj.data = DICT_DEFAULT_STORAGE_SYSTEM_500
        self.resource.add.return_value = obj

        self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM_500)

        StorageSystemModule().run()

        self.resource.add.assert_called_once_with(
            {
                'username': '******',
                'password': '******',
                'hostname': '10.0.0.0',
                'family': 'StoreServ'
            }
        )

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=StorageSystemModule.MSG_ADDED,
            ansible_facts=dict(storage_system=DICT_DEFAULT_STORAGE_SYSTEM_500)
        )
    def test_should_fail_when_credentials_attribute_is_missing(self):
        self.resource.get_by_name.return_value = []

        self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM_BY_NAME)

        StorageSystemModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=StorageSystemModule.MSG_CREDENTIALS_MANDATORY)
    def test_should_fail_with_missing_required_attributes(self):
        self.mock_ansible_module.params = {"state": "present",
                                           "config": "config",
                                           "data":
                                               {"field": "invalid"}}

        StorageSystemModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=StorageSystemModule.MSG_MANDATORY_FIELDS_MISSING)
示例#4
0
    def test_should_do_nothing_when_storage_system_not_exist(self):
        self.resource.get_by_ip_hostname.return_value = []

        self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM_ABSENT)

        StorageSystemModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False, msg=StorageSystemModule.MSG_ALREADY_ABSENT)
示例#5
0
    def test_should_remove_storage_system(self):
        obj = mock.Mock()
        obj.data = DICT_DEFAULT_STORAGE_SYSTEM
        self.resource.get_by_ip_hostname.return_value = obj

        self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM_ABSENT)

        StorageSystemModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True, msg=StorageSystemModule.MSG_DELETED)
示例#6
0
 def test_should_add_new_storage_system_with_credentials_from_api300(self):
     self.resource.get_by_ip_hostname.return_value = None
     obj = mock.Mock()
     obj.data = DICT_DEFAULT_STORAGE_SYSTEM
     self.resource.add.return_value = obj
     self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM)
     StorageSystemModule().run()
     self.mock_ansible_module.exit_json.assert_called_once_with(
         changed=True,
         msg=StorageSystemModule.MSG_ADDED,
         ansible_facts=dict(storage_system=DICT_DEFAULT_STORAGE_SYSTEM))
    def test_should_not_update_when_data_is_equals_using_name(self):
        dict_by_name = yaml.load(YAML_STORAGE_SYSTEM_BY_NAME)["data"]
        self.resource.data = dict_by_name
        self.resource.get_by_name.return_value = self.resource

        self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM_BY_NAME)

        StorageSystemModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=StorageSystemModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(storage_system=dict_by_name)
        )
示例#8
0
    def test_should_not_update_when_data_is_equals(self):
        obj = mock.Mock()
        obj.data = DICT_DEFAULT_STORAGE_SYSTEM
        self.resource.get_by_ip_hostname.return_value = obj
        self.resource.update.return_value = DICT_DEFAULT_STORAGE_SYSTEM

        self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM)

        StorageSystemModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=StorageSystemModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(storage_system=DICT_DEFAULT_STORAGE_SYSTEM))
    def test_update_when_data_has_modified_attributes(self):
        data_merged = DICT_DEFAULT_STORAGE_SYSTEM.copy()
        data_merged['credentials']['newIp_hostname'] = '10.10.10.10'

        obj = mock.Mock()
        obj.data = DICT_DEFAULT_STORAGE_SYSTEM
        self.resource.get_by_ip_hostname.return_value = obj
        self.resource.update.return_value = data_merged

        self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM_CHANGES)

        StorageSystemModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=StorageSystemModule.MSG_UPDATED,
            ansible_facts=dict(storage_system=data_merged)
        )