コード例 #1
0
    def test_should_fail_when_get_by_name_raises_exception(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.get_by.side_effect = Exception(ERROR_MSG)

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_PRESENT)
        mock_ansible_module.return_value = mock_ansible_instance

        UnmanagedDeviceModule().run()

        mock_ansible_instance.fail_json.assert_called_once_with(msg=ERROR_MSG)
コード例 #2
0
    def test_should_do_nothing_when_not_exist(self):
        self.resource.get_by.return_value = []

        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        UnmanagedDeviceModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=NOTHING_TO_DO
        )
コード例 #3
0
    def test_should_load_config_from_file(self, mock_ansible_module, mock_ov_client_from_env_vars,
                                          mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock({'config': 'config.json'})
        mock_ansible_module.return_value = mock_ansible_instance

        UnmanagedDeviceModule()

        mock_ov_client_from_json_file.assert_called_once_with('config.json')
        mock_ov_client_from_env_vars.not_been_called()
コード例 #4
0
    def test_should_delete_all_resources(self):
        self.resource.remove_all.return_value = [UNMANAGED_DEVICE]

        self.mock_ansible_module.params = PARAMS_FOR_REMOVE_ALL

        UnmanagedDeviceModule().run()

        self.resource.remove_all.assert_called_once_with(filter=FILTER)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UNMANAGED_DEVICE_SET_REMOVED
        )
コード例 #5
0
    def test_should_remove_the_unmanaged_device(self):
        self.resource.get_by.return_value = [UNMANAGED_DEVICE]
        self.resource.remove.return_value = True

        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        UnmanagedDeviceModule().run()

        self.resource.remove.assert_called_once_with(UNMANAGED_DEVICE)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UNMANAGED_DEVICE_REMOVED
        )
コード例 #6
0
    def test_should_do_nothing_when_not_exist(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.get_by.return_value = []

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_ABSENT)
        mock_ansible_module.return_value = mock_ansible_instance

        UnmanagedDeviceModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            msg=NOTHING_TO_DO
        )
コード例 #7
0
    def test_should_add(self):
        self.resource.get_by.return_value = []
        self.resource.add.return_value = UNMANAGED_DEVICE

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        UnmanagedDeviceModule().run()

        self.resource.get_by.assert_called_once_with('name', UNMANAGED_DEVICE_NAME)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UNMANAGED_DEVICE_ADDED,
            ansible_facts=dict(unmanaged_device=UNMANAGED_DEVICE)
        )
コード例 #8
0
    def test_should_not_update_when_data_is_equals(self, mock_resource_compare):
        self.resource.get_by.return_value = [UNMANAGED_DEVICE_FOR_PRESENT]

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        mock_resource_compare.return_value = True

        UnmanagedDeviceModule().run()

        self.resource.get_by.assert_called_once_with('name', UNMANAGED_DEVICE_NAME)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=NOTHING_TO_DO,
            ansible_facts=dict(unmanaged_device=UNMANAGED_DEVICE_FOR_PRESENT)
        )
コード例 #9
0
    def test_should_fail_when_update_raises_exception(self, mock_ansible_module,
                                                      mock_ov_from_file, mock_resource_compare):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.get_by.return_value = [UNMANAGED_DEVICE]
        mock_ov_instance.unmanaged_devices.update.side_effect = Exception(ERROR_MSG)

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_PRESENT)
        mock_ansible_module.return_value = mock_ansible_instance

        mock_resource_compare.return_value = False

        UnmanagedDeviceModule().run()

        mock_ov_instance.unmanaged_devices.update.assert_called_once_with(UNMANAGED_DEVICE)
        mock_ansible_instance.fail_json.assert_called_once_with(msg=ERROR_MSG)
コード例 #10
0
    def test_should_delete_all_resources(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.remove_all.return_value = [UNMANAGED_DEVICE]

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_REMOVE_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        UnmanagedDeviceModule().run()

        mock_ov_instance.unmanaged_devices.remove_all.assert_called_once_with(filter=FILTER)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=UNMANAGED_DEVICE_SET_REMOVED
        )
コード例 #11
0
    def test_should_remove_the_unmanaged_device(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.get_by.return_value = [UNMANAGED_DEVICE]
        mock_ov_instance.unmanaged_devices.remove.return_value = True

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_ABSENT)
        mock_ansible_module.return_value = mock_ansible_instance

        UnmanagedDeviceModule().run()

        mock_ov_instance.unmanaged_devices.remove.assert_called_once_with(UNMANAGED_DEVICE)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=UNMANAGED_DEVICE_REMOVED
        )
コード例 #12
0
    def test_should_add(self, mock_ansible_module, mock_ov_from_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.get_by.return_value = []
        mock_ov_instance.unmanaged_devices.add.return_value = UNMANAGED_DEVICE

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_PRESENT)
        mock_ansible_module.return_value = mock_ansible_instance

        UnmanagedDeviceModule().run()

        mock_ov_instance.unmanaged_devices.get_by.assert_called_once_with('name', UNMANAGED_DEVICE_NAME)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=UNMANAGED_DEVICE_ADDED,
            ansible_facts=dict(unmanaged_device=UNMANAGED_DEVICE)
        )
コード例 #13
0
    def test_should_not_update_when_data_is_equals(self, mock_ansible_module, mock_ov_from_file, mock_resource_compare):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.get_by.return_value = [UNMANAGED_DEVICE_FOR_PRESENT]

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_PRESENT)
        mock_ansible_module.return_value = mock_ansible_instance

        mock_resource_compare.return_value = True

        UnmanagedDeviceModule().run()

        mock_ov_instance.unmanaged_devices.get_by.assert_called_once_with('name', UNMANAGED_DEVICE_NAME)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            msg=NOTHING_TO_DO,
            ansible_facts=dict(unmanaged_device=UNMANAGED_DEVICE_FOR_PRESENT)
        )
コード例 #14
0
    def test_should_update_the_unmanaged_device(self, mock_resource_compare):
        self.resource.get_by.return_value = [UNMANAGED_DEVICE_FOR_PRESENT]
        self.resource.update.return_value = UNMANAGED_DEVICE

        params_update = PARAMS_FOR_PRESENT.copy()
        params_update['data']['newName'] = 'UD New Name'

        self.mock_ansible_module.params = params_update

        mock_resource_compare.return_value = False

        UnmanagedDeviceModule().run()

        self.resource.get_by.assert_called_once_with('name', UNMANAGED_DEVICE_NAME)
        self.resource.update.assert_called_once_with(UNMANAGED_DEVICE_FOR_PRESENT)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UNMANAGED_DEVICE_UPDATED,
            ansible_facts=dict(unmanaged_device=UNMANAGED_DEVICE)
        )
コード例 #15
0
    def test_should_update_the_unmanaged_device(self, mock_ansible_module, mock_ov_from_file, mock_resource_compare):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.unmanaged_devices.get_by.return_value = [UNMANAGED_DEVICE_FOR_PRESENT]
        mock_ov_instance.unmanaged_devices.update.return_value = UNMANAGED_DEVICE

        mock_ov_from_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_FOR_PRESENT)
        mock_ansible_module.return_value = mock_ansible_instance

        mock_resource_compare.return_value = False

        UnmanagedDeviceModule().run()

        mock_ov_instance.unmanaged_devices.get_by.assert_called_once_with('name', UNMANAGED_DEVICE_NAME)
        mock_ov_instance.unmanaged_devices.update.assert_called_once_with(UNMANAGED_DEVICE_FOR_PRESENT)

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=UNMANAGED_DEVICE_UPDATED,
            ansible_facts=dict(unmanaged_device=UNMANAGED_DEVICE)
        )