예제 #1
0
    def test_should_delete(self):
        self.resource.get_by.return_value = self.EXISTENT_UPLINK_SETS

        self.mock_ansible_module.params = self.PARAMS_FOR_ABSENT

        UplinkSetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True, msg=UPLINK_SET_DELETED)
예제 #2
0
    def test_should_do_nothing_when_not_exist(self):
        self.resource.get_by.return_value = []

        self.mock_ansible_module.params = self.PARAMS_FOR_ABSENT

        UplinkSetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False, msg=UPLINK_SET_ALREADY_ABSENT)
예제 #3
0
    def test_should_fail_when_logical_interconnect_name_not_set(self):
        params = self.PARAMS_FOR_ABSENT_WITH_LI_NAME.copy()
        params['data'].pop('logicalInterconnectName')

        self.mock_ansible_module.params = params

        UplinkSetModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=UPLINK_SET_KEY_REQUIRED)
예제 #4
0
    def test_should_not_update_when_data_is_equals(self):
        self.resource.get_by.return_value = self.EXISTENT_UPLINK_SETS

        self.mock_ansible_module.params = self.PARAMS_FOR_PRESENT

        UplinkSetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=UPLINK_SET_ALREADY_EXIST,
            ansible_facts=dict(uplink_set=self.UPLINK_SET_FOUND_BY_KEY))
예제 #5
0
    def test_should_create(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = self.UPLINK_SET_FOUND_BY_KEY

        self.mock_ansible_module.params = self.PARAMS_FOR_PRESENT

        UplinkSetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UPLINK_SET_CREATED,
            ansible_facts=dict(uplink_set=self.UPLINK_SET_FOUND_BY_KEY))
    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

        UplinkSetModule()

        mock_ov_client_from_json_file.assert_called_once_with('config.json')
        mock_ov_client_from_env_vars.not_been_called()
예제 #7
0
    def test_should_fail_when_logical_interconnect_not_found(self):
        self.resource.get_by.return_value = []
        self.mock_ov_client.logical_interconnects.get_by_name.return_value = None

        self.mock_ansible_module.params = self.PARAMS_FOR_PRESENT_WITH_LI_NAME

        UplinkSetModule().run()

        self.mock_ov_client.logical_interconnects.get_by_name.assert_called_once_with(
            'Name of the Logical Interconnect')

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=UPLINK_SET_LOGICAL_INTERCONNECT_NOT_FOUND)
예제 #8
0
    def test_should_replace_logical_interconnect_name_by_uri_absent(self):
        self.resource.get_by.return_value = self.EXISTENT_UPLINK_SETS
        self.mock_ov_client.logical_interconnects.get_by_name.return_value = self.LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = self.PARAMS_FOR_ABSENT_WITH_LI_NAME.copy(
        )

        UplinkSetModule().run()

        self.mock_ov_client.logical_interconnects.get_by_name.assert_called_once_with(
            'Name of the Logical Interconnect')
        self.resource.delete.assert_called_once_with(
            self.UPLINK_SET_FOUND_BY_KEY)
    def test_should_do_nothing_when_not_exist(self, mock_ansible_module,
                                              mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.uplink_sets.get_by.return_value = []

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

        UplinkSetModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False, msg=UPLINK_SET_ALREADY_ABSENT)
    def test_should_delete(self, mock_ansible_module,
                           mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.uplink_sets.get_by.return_value = EXISTENT_UPLINK_SETS

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

        UplinkSetModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True, msg=UPLINK_SET_DELETED)
예제 #11
0
    def test_rename_when_resource_exists(self):
        data_merged = self.UPLINK_SET_FOUND_BY_KEY.copy()
        data_merged['name'] = RENAMED_UPLINK_SET
        params_to_rename = self.PARAMS_TO_RENAME.copy()

        self.resource.get_by = mock.MagicMock(
            side_effect=[self.EXISTENT_UPLINK_SETS, []])
        self.resource.update.return_value = data_merged

        self.mock_ansible_module.params = params_to_rename

        UplinkSetModule().run()

        self.resource.update.assert_called_once_with(data_merged)
    def test_should_fail_when_logical_interconnect_name_not_set(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        params = PARAMS_FOR_ABSENT_WITH_LI_NAME.copy()
        params['data'].pop('logicalInterconnectName')

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(params)
        mock_ansible_module.return_value = mock_ansible_instance

        self.assertRaises(Exception, UplinkSetModule().run())

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=UPLINK_SET_KEY_REQUIRED)
    def test_should_not_update_when_data_is_equals(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.uplink_sets.get_by.return_value = EXISTENT_UPLINK_SETS

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

        UplinkSetModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            msg=UPLINK_SET_ALREADY_EXIST,
            ansible_facts=dict(uplink_set=UPLINK_SET_FOUND_BY_KEY))
예제 #14
0
    def test_update_when_data_has_modified_attributes(self):
        data_merged = self.UPLINK_SET_FOUND_BY_KEY.copy()
        data_merged['description'] = 'New description'

        self.resource.get_by.return_value = self.EXISTENT_UPLINK_SETS
        self.resource.update.return_value = data_merged

        self.mock_ansible_module.params = self.PARAMS_WITH_CHANGES

        UplinkSetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UPLINK_SET_UPDATED,
            ansible_facts=dict(uplink_set=data_merged))
    def test_should_fail_when_delete_raises_exception(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.uplink_sets.get_by.return_value = EXISTENT_UPLINK_SETS
        mock_ov_instance.uplink_sets.delete.side_effect = Exception(
            FAKE_MSG_ERROR)

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

        self.assertRaises(Exception, UplinkSetModule().run())

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=FAKE_MSG_ERROR)
    def test_should_create(self, mock_ansible_module,
                           mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.uplink_sets.get_by.return_value = []
        mock_ov_instance.uplink_sets.create.return_value = UPLINK_SET_FOUND_BY_KEY

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

        UplinkSetModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=UPLINK_SET_CREATED,
            ansible_facts=dict(uplink_set=UPLINK_SET_FOUND_BY_KEY))
    def test_should_replace_logical_interconnect_name_by_uri(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.uplink_sets.get_by.return_value = EXISTENT_UPLINK_SETS
        mock_ov_instance.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(
            PARAMS_FOR_ABSENT_WITH_LI_NAME)
        mock_ansible_module.return_value = mock_ansible_instance

        UplinkSetModule().run()

        mock_ov_instance.logical_interconnects.get_by_name.assert_called_once_with(
            'Name of the Logical Interconnect')
        mock_ov_instance.uplink_sets.delete.assert_called_once_with(
            UPLINK_SET_FOUND_BY_KEY)
예제 #18
0
    def test_should_replace_logical_interconnect_name_by_uri(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = self.UPLINK_SET_FOUND_BY_KEY
        self.mock_ov_client.logical_interconnects.get_by_name.return_value = self.LOGICAL_INTERCONNECT

        self.mock_ansible_module.params = self.PARAMS_FOR_PRESENT_WITH_LI_NAME

        UplinkSetModule().run()

        self.mock_ov_client.logical_interconnects.get_by_name.assert_called_once_with(
            'Name of the Logical Interconnect')
        self.resource.create.assert_called_once_with(
            self.PARAMS_FOR_PRESENT['data'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UPLINK_SET_CREATED,
            ansible_facts=dict(uplink_set=self.UPLINK_SET_FOUND_BY_KEY))
    def test_update_when_data_has_modified_attributes(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        data_merged = UPLINK_SET_FOUND_BY_KEY.copy()
        data_merged['description'] = 'New description'

        mock_ov_instance = mock.Mock()
        mock_ov_instance.uplink_sets.get_by.return_value = EXISTENT_UPLINK_SETS
        mock_ov_instance.uplink_sets.update.return_value = data_merged

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(PARAMS_WITH_CHANGES)
        mock_ansible_module.return_value = mock_ansible_instance

        UplinkSetModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=UPLINK_SET_UPDATED,
            ansible_facts=dict(uplink_set=data_merged))
    def test_rename_when_resource_exists(self, mock_ansible_module,
                                         mock_ov_client_from_json_file):
        data_merged = UPLINK_SET_FOUND_BY_KEY.copy()
        data_merged['name'] = RENAMED_UPLINK_SET
        params_to_rename = PARAMS_TO_RENAME.copy()

        mock_ov_instance = mock.Mock()
        mock_ov_instance.uplink_sets.get_by = mock.MagicMock(
            side_effect=[EXISTENT_UPLINK_SETS, []])
        mock_ov_instance.uplink_sets.update.return_value = data_merged

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock(params_to_rename)
        mock_ansible_module.return_value = mock_ansible_instance

        UplinkSetModule().run()

        mock_ov_instance.uplink_sets.update.assert_called_once_with(
            data_merged)