Exemplo n.º 1
0
    def test_update_scopes_when_different(self):
        params_to_scope = yaml.load(YAML_LOGICAL_SWITCH_GROUP).copy()
        params_to_scope['data']['scopeUris'] = ['test']
        params_to_scope['data']['uri'] = 'rest/fw/fake'
        self.mock_ansible_module.params = params_to_scope

        different_resource = params_to_scope['data'].copy()
        different_resource['scopeUris'] = ['fake']
        self.resource.data = different_resource
        obj = mock.Mock()
        obj.data = {'uri': SWITCH_TYPE_URI}
        self.mock_ov_client.switch_types.get_by_name.return_value = obj

        obj1 = mock.Mock()
        obj1.data = params_to_scope['data']
        self.resource.patch.return_value = obj1

        LogicalSwitchGroupModule().run()

        self.resource.patch.assert_called_once_with(operation='replace',
                                                    path='/scopeUris',
                                                    value=['test'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            ansible_facts=dict(logical_switch_group=params_to_scope['data']),
            msg=LogicalSwitchGroupModule.MSG_UPDATED
        )
Exemplo n.º 2
0
    def test_should_fail_when_switch_type_was_not_found(self):
        self.resource.get_by_name.return_value = None
        self.mock_ov_client.switch_types.get_by_name.return_value = None

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

        LogicalSwitchGroupModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=LogicalSwitchGroupModule.MSG_SWITCH_TYPE_NOT_FOUND)
Exemplo n.º 3
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(
            changed=False, msg=LogicalSwitchGroupModule.MSG_ALREADY_ABSENT)
Exemplo n.º 4
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(
            changed=True, msg=LogicalSwitchGroupModule.MSG_DELETED)
Exemplo n.º 5
0
    def test_should_update_the_logical_switch_group(self):
        self.resource.data = DICT_DEFAULT_LOGICAL_SWITCH_GROUP

        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=LogicalSwitchGroupModule.MSG_UPDATED,
            ansible_facts=dict(logical_switch_group=self.resource.data)
        )
Exemplo n.º 6
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=LogicalSwitchGroupModule.MSG_CREATED,
            ansible_facts=dict(logical_switch_group={"name": "name"})
        )
Exemplo n.º 7
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=LogicalSwitchGroupModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(logical_switch_group=DICT_DEFAULT_LOGICAL_SWITCH_GROUP)
        )
Exemplo n.º 8
0
    def test_should_do_nothing_when_scopes_are_the_same(self):
        params_to_scope = yaml.load(YAML_LOGICAL_SWITCH_GROUP).copy()
        params_to_scope['data']['scopeUris'] = ['test']
        self.mock_ansible_module.params = params_to_scope

        resource_data = params_to_scope['data'].copy()
        resource_data['scopeUris'] = ['test']
        self.resource.get_by.return_value = [resource_data]
        self.mock_ov_client.switch_types.get_by.return_value = [{'uri': SWITCH_TYPE_URI}]

        LogicalSwitchGroupModule().run()

        self.resource.patch.not_been_called()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(logical_switch_group=resource_data),
            msg=LogicalSwitchGroupModule.MSG_ALREADY_PRESENT
        )