def test_should_raise_exception_when_api_is_lower_than_600(self):
        self.mock_ov_client.api_version = 400
        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        ApplianceDeviceSnmpV3UsersModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY,
            msg=ApplianceDeviceSnmpV3UsersModule.MSG_API_VERSION_ERROR
        )
    def test_should_remove_snmp_v3_user(self):
        self.resource.get_by.return_value = [DEFAULT_PARAMS]
        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        ApplianceDeviceSnmpV3UsersModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ApplianceDeviceSnmpV3UsersModule.MSG_DELETED
        )
    def test_should_do_nothing_when_snmp_v3_user_not_exist(self):
        self.resource.get_by_name.return_value = []

        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        ApplianceDeviceSnmpV3UsersModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ApplianceDeviceSnmpV3UsersModule.MSG_ALREADY_ABSENT
        )
Пример #4
0
    def test_should_raise_exception_when_user_does_not_exists_for_set_password(self):
        self.resource.get_by.return_value = []

        self.mock_ansible_module.params = PARAMS_FOR_SET_PASSWORD

        ApplianceDeviceSnmpV3UsersModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY,
            msg='The specified user does not exist.'
        )
Пример #5
0
    def test_should_create_new_snmp_v3_user(self):
        self.resource.create.return_value = DEFAULT_PARAMS

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        ApplianceDeviceSnmpV3UsersModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ApplianceDeviceSnmpV3UsersModule.MSG_CREATED,
            ansible_facts=dict(appliance_device_snmp_v3_users=DEFAULT_PARAMS)
        )
Пример #6
0
    def test_should_raise_exception_when_user_id_or_username_not_provided(self):
        data_missing = PARAMS_FOR_PRESENT.copy()
        data_missing['data'].pop('userName')

        self.mock_ansible_module.params = data_missing

        ApplianceDeviceSnmpV3UsersModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY,
            msg=ApplianceDeviceSnmpV3UsersModule.MSG_VALUE_ERROR
        )
Пример #7
0
    def test_should_not_update_when_data_is_equals(self):
        self.resource.get_by.return_value = [DEFAULT_PARAMS]

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        ApplianceDeviceSnmpV3UsersModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ApplianceDeviceSnmpV3UsersModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(appliance_device_snmp_v3_users=DEFAULT_PARAMS)
        )
Пример #8
0
    def test_should_raise_exception_when_password_not_provided_for_set_password(self):
        self.resource.get_by.return_value = [DEFAULT_PARAMS]
        data_for_comparison = PARAMS_FOR_SET_PASSWORD.copy()
        data_for_comparison['data'].pop('authenticationPassphrase')

        self.mock_ansible_module.params = data_for_comparison

        ApplianceDeviceSnmpV3UsersModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY,
            msg='This state requires an authenticationPassphrase to be declared.'
        )
Пример #9
0
    def test_should_set_password_for_a_user(self):
        self.resource.get_by.return_value = [DEFAULT_PARAMS]
        self.resource.update.return_value = DEFAULT_PARAMS

        self.mock_ansible_module.params = PARAMS_FOR_SET_PASSWORD

        ApplianceDeviceSnmpV3UsersModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ApplianceDeviceSnmpV3UsersModule.MSG_PASSWORD_UPDATED,
            ansible_facts=dict(appliance_device_snmp_v3_users=DEFAULT_PARAMS)
        )
    def test_update_when_data_has_modified_attributes(self):
        data_merged = DEFAULT_PARAMS.copy()
        self.resource.data = DEFAULT_PARAMS
        self.resource.get_by_name.return_value = self.resource
        self.resource.update.return_value = data_merged

        self.mock_ansible_module.params = PARAMS_WITH_CHANGES

        ApplianceDeviceSnmpV3UsersModule().run()

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