示例#1
0
    def test_should_not_update_when_data_is_equals(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        switch_type_replaced = DICT_DEFAULT_LOGICAL_SWITCH_GROUP.copy()
        del switch_type_replaced['switchMapTemplate'][
            'switchMapEntryTemplates'][0]['permittedSwitchTypeName']

        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_switch_groups.get_by.return_value = [
            DICT_DEFAULT_LOGICAL_SWITCH_GROUP
        ]
        mock_ov_instance.switch_types.get_by.return_value = [{
            'uri':
            SWITCH_TYPE_URI
        }]

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_LOGICAL_SWITCH_GROUP)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalSwitchGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            msg=LOGICAL_SWITCH_GROUP_ALREADY_UPDATED,
            ansible_facts=dict(
                logical_switch_group=DICT_DEFAULT_LOGICAL_SWITCH_GROUP))
示例#2
0
    def test_should_fail_when_switch_type_was_not_found(self):
        self.resource.get_by.return_value = []
        self.mock_ov_client.switch_types.get_by.return_value = []

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

        LogicalSwitchGroupModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=SWITCH_TYPE_NOT_FOUND)
示例#3
0
    def test_should_remove_logical_switch_group(self):
        self.resource.get_by.return_value = [DICT_DEFAULT_LOGICAL_SWITCH_GROUP]

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

        LogicalSwitchGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            ansible_facts={}, changed=True, msg=LOGICAL_SWITCH_GROUP_DELETED)
示例#4
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

        LogicalSwitchGroupModule()

        mock_ov_client_from_json_file.assert_called_once_with('config.json')
        mock_ov_client_from_env_vars.not_been_called()
示例#5
0
    def test_should_do_nothing_when_logical_switch_group_not_exist(self):
        self.resource.get_by.return_value = []

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

        LogicalSwitchGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            ansible_facts={},
            changed=False,
            msg=LOGICAL_SWITCH_GROUP_ALREADY_ABSENT)
示例#6
0
    def test_should_update_the_logical_switch_group(self):
        self.resource.get_by.return_value = [DICT_DEFAULT_LOGICAL_SWITCH_GROUP]
        self.resource.update.return_value = {"name": "name"}

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

        LogicalSwitchGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LOGICAL_SWITCH_GROUP_UPDATED,
            ansible_facts=dict(logical_switch_group={"name": "name"}))
示例#7
0
    def test_should_do_nothing_when_logical_switch_group_not_exist(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_switch_groups.get_by.return_value = []

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_LOGICAL_SWITCH_GROUP_ABSENT)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalSwitchGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            ansible_facts={},
            changed=False,
            msg=LOGICAL_SWITCH_GROUP_ALREADY_ABSENT)
示例#8
0
    def test_should_remove_logical_switch_group(self, mock_ansible_module,
                                                mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_switch_groups.get_by.return_value = [
            DICT_DEFAULT_LOGICAL_SWITCH_GROUP
        ]

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_LOGICAL_SWITCH_GROUP_ABSENT)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalSwitchGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            ansible_facts={}, changed=True, msg=LOGICAL_SWITCH_GROUP_DELETED)
示例#9
0
    def test_should_create_new_logical_switch_group(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = {"name": "name"}
        self.mock_ov_client.switch_types.get_by.return_value = [{
            'uri':
            SWITCH_TYPE_URI
        }]

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

        LogicalSwitchGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LOGICAL_SWITCH_GROUP_CREATED,
            ansible_facts=dict(logical_switch_group={"name": "name"}))
示例#10
0
    def test_should_fail_when_switch_type_was_not_found(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_switch_groups.get_by.return_value = []
        mock_ov_instance.logical_switch_groups.create.side_effect = Exception(
            FAKE_MSG_ERROR)
        mock_ov_instance.switch_types.get_by.return_value = []

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_LOGICAL_SWITCH_GROUP)
        mock_ansible_module.return_value = mock_ansible_instance

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

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=SWITCH_TYPE_NOT_FOUND)
示例#11
0
    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.logical_switch_groups.get_by.return_value = [
            DICT_DEFAULT_LOGICAL_SWITCH_GROUP
        ]
        mock_ov_instance.logical_switch_groups.delete.side_effect = Exception(
            FAKE_MSG_ERROR)

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_LOGICAL_SWITCH_GROUP_ABSENT)
        mock_ansible_module.return_value = mock_ansible_instance

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

        mock_ansible_instance.fail_json.assert_called_once_with(
            msg=FAKE_MSG_ERROR)
示例#12
0
    def test_should_not_update_when_data_is_equals(self):
        switch_type_replaced = DICT_DEFAULT_LOGICAL_SWITCH_GROUP.copy()
        del switch_type_replaced['switchMapTemplate'][
            'switchMapEntryTemplates'][0]['permittedSwitchTypeName']

        self.resource.get_by.return_value = [DICT_DEFAULT_LOGICAL_SWITCH_GROUP]
        self.mock_ov_client.switch_types.get_by.return_value = [{
            'uri':
            SWITCH_TYPE_URI
        }]

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

        LogicalSwitchGroupModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LOGICAL_SWITCH_GROUP_ALREADY_UPDATED,
            ansible_facts=dict(
                logical_switch_group=DICT_DEFAULT_LOGICAL_SWITCH_GROUP))
示例#13
0
    def test_should_update_the_logical_switch_group(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_switch_groups.get_by.return_value = [
            DICT_DEFAULT_LOGICAL_SWITCH_GROUP
        ]
        mock_ov_instance.logical_switch_groups.update.return_value = {
            "name": "name"
        }

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_LOGICAL_SWITCH_GROUP_CHANGE)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalSwitchGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=LOGICAL_SWITCH_GROUP_UPDATED,
            ansible_facts=dict(logical_switch_group={"name": "name"}))
示例#14
0
    def test_should_create_new_logical_switch_group(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.logical_switch_groups.get_by.return_value = []
        mock_ov_instance.logical_switch_groups.create.return_value = {
            "name": "name"
        }
        mock_ov_instance.switch_types.get_by.return_value = [{
            'uri':
            SWITCH_TYPE_URI
        }]

        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock_yaml(
            YAML_LOGICAL_SWITCH_GROUP)
        mock_ansible_module.return_value = mock_ansible_instance

        LogicalSwitchGroupModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=True,
            msg=LOGICAL_SWITCH_GROUP_CREATED,
            ansible_facts=dict(logical_switch_group={"name": "name"}))