Ejemplo n.º 1
0
    def test_should_update_with_current_switches_and_group_when_not_provided(
            self):
        self.resource.get_by.side_effect = [[LOGICAL_SWITCH_FROM_ONEVIEW], []]
        self.resource.update.return_value = LOGICAL_SWITCH_FROM_ONEVIEW
        self.mock_ansible_module.params = PARAMS_FOR_UPDATE

        LogicalSwitchModule().run()

        data_for_update = {
            'logicalSwitch': {
                'name':
                'Test Logical Switch - Renamed',
                'uri':
                '/rest/logical-switches/f0d7ad37-2053-46ac-bb11-4ebdd079bb66',
                'logicalSwitchGroupUri':
                '/rest/logical-switch-groups/af370d9a-f2f4-4beb-a1f1-670930d6741d',
                'switchCredentialConfiguration': [{
                    'logicalSwitchManagementHost':
                    '172.16.1.1'
                }, {
                    'logicalSwitchManagementHost':
                    '172.16.1.2'
                }],
            },
            'logicalSwitchCredentials': []
        }
        self.resource.update.assert_called_once_with(data_for_update)
Ejemplo n.º 2
0
    def test_should_update_with_given_switches_and_group_when_provided(self):
        self.resource.get_by.side_effect = [[LOGICAL_SWITCH_FROM_ONEVIEW], []]
        self.resource.update.return_value = LOGICAL_SWITCH_FROM_ONEVIEW
        self.logical_switch_group_client.get_by.return_value = [{
            'uri':
            '/rest/logical-switch-groups/aa-bb-cc'
        }]

        self.mock_ansible_module.params = PARAMS_FOR_UPDATE_WITH_SWITCHES_AND_GROUPS

        LogicalSwitchModule().run()

        data_for_update = {
            'logicalSwitch': {
                'name':
                'Test Logical Switch',
                'uri':
                LOGICAL_SWITCH_FROM_ONEVIEW['uri'],
                'logicalSwitchGroupUri':
                '/rest/logical-switch-groups/aa-bb-cc',
                'switchCredentialConfiguration': [{
                    'logicalSwitchManagementHost':
                    '172.16.1.3'
                }, {
                    'logicalSwitchManagementHost':
                    '172.16.1.4'
                }],
            },
            'logicalSwitchCredentials': []
        }
        self.resource.update.assert_called_once_with(data_for_update)
Ejemplo n.º 3
0
    def test_should_do_nothing_when_logical_switch_not_exist(self):
        self.resource.get_by.return_value = []
        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        LogicalSwitchModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False, msg=LogicalSwitchModule.MSG_ALREADY_ABSENT)
Ejemplo n.º 4
0
    def test_should_delete_logical_switch(self):
        self.resource.get_by.return_value = [LOGICAL_SWITCH_FROM_ONEVIEW]
        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        LogicalSwitchModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True, msg=LogicalSwitchModule.MSG_DELETED)
Ejemplo n.º 5
0
    def test_should_fail_on_update_when_logical_switch_attribute_missing(self):
        params = deepcopy(PARAMS_FOR_UPDATE_WITH_SWITCHES_AND_GROUPS)
        del params['data']['logicalSwitch']
        self.mock_ansible_module.params = params

        LogicalSwitchModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=LogicalSwitchModule.MSG_LOGICAL_SWITCH_NOT_FOUND)
Ejemplo n.º 6
0
    def test_should_fail_when_logical_switch_not_found(self):
        self.resource.get_by.return_value = []
        self.resource.refresh.return_value = LOGICAL_SWITCH_FROM_ONEVIEW

        self.mock_ansible_module.params = PARAMS_FOR_REFRESH

        LogicalSwitchModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=LogicalSwitchModule.MSG_LOGICAL_SWITCH_NOT_FOUND)
Ejemplo n.º 7
0
    def test_should_fail_when_group_not_found_for_update(self):
        self.resource.get_by.side_effect = [[LOGICAL_SWITCH_FROM_ONEVIEW], []]
        self.resource.update.return_value = LOGICAL_SWITCH_FROM_ONEVIEW
        self.logical_switch_group_client.get_by.return_value = []
        self.mock_ansible_module.params = PARAMS_FOR_UPDATE_WITH_SWITCHES_AND_GROUPS

        LogicalSwitchModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=LogicalSwitchModule.MSG_LOGICAL_SWITCH_GROUP_NOT_FOUND)
Ejemplo n.º 8
0
    def test_should_fail_when_group_not_found(self):
        self.resource.get_by.return_value = []
        self.logical_switch_group_client.get_by.return_value = []
        self.resource.create.return_value = LOGICAL_SWITCH_FROM_ONEVIEW
        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        LogicalSwitchModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=LogicalSwitchModule.MSG_LOGICAL_SWITCH_GROUP_NOT_FOUND)
Ejemplo n.º 9
0
    def test_should_refresh_logical_switch(self):
        self.resource.get_by.return_value = [LOGICAL_SWITCH_FROM_ONEVIEW]
        self.resource.refresh.return_value = LOGICAL_SWITCH_FROM_ONEVIEW

        self.mock_ansible_module.params = PARAMS_FOR_REFRESH

        LogicalSwitchModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            ansible_facts=dict(logical_switch=LOGICAL_SWITCH_FROM_ONEVIEW),
            msg=LogicalSwitchModule.MSG_REFRESHED)
Ejemplo n.º 10
0
    def test_should_not_update_when_logical_switch_not_found(self):
        self.resource.get_by.side_effect = [[], []]
        self.resource.update.return_value = LOGICAL_SWITCH_FROM_ONEVIEW
        self.logical_switch_group_client.get_by.return_value = [{
            'uri':
            '/rest/logical-switch-groups/aa-bb-cc'
        }]
        self.mock_ansible_module.params = PARAMS_FOR_UPDATE

        LogicalSwitchModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=LogicalSwitchModule.MSG_LOGICAL_SWITCH_NOT_FOUND)
Ejemplo n.º 11
0
    def test_should_not_create_when_logical_switch_already_exist(self):
        self.resource.get_by.return_value = [LOGICAL_SWITCH_FROM_ONEVIEW]
        self.logical_switch_group_client.get_by.return_value = [{
            'uri':
            '/rest/logical-switch-groups/aa-bb-cc'
        }]
        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        LogicalSwitchModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=LogicalSwitchModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(logical_switch=LOGICAL_SWITCH_FROM_ONEVIEW))
Ejemplo n.º 12
0
    def test_should_create_new_logical_switch(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = LOGICAL_SWITCH_FROM_ONEVIEW
        self.logical_switch_group_client.get_by.return_value = [{
            'uri':
            '/rest/logical-switch-groups/aa-bb-cc'
        }]
        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        LogicalSwitchModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=LogicalSwitchModule.MSG_CREATED,
            ansible_facts=dict(logical_switch=LOGICAL_SWITCH_FROM_ONEVIEW))
Ejemplo n.º 13
0
    def test_update_scopes_when_different(self):
        self.resource.get_by.side_effect = [[LOGICAL_SWITCH_FROM_ONEVIEW], []]
        self.resource.update.return_value = LOGICAL_SWITCH_FROM_ONEVIEW
        self.logical_switch_group_client.get_by.return_value = [{
            'uri':
            '/rest/logical-switch-groups/aa-bb-cc'
        }]

        self.mock_ansible_module.params = PARAMS_FOR_UPDATE_WITH_SWITCHES_AND_GROUPS
        self.resource.patch.return_value = LOGICAL_SWITCH_FROM_ONEVIEW

        LogicalSwitchModule().run()

        data_for_update = {
            'logicalSwitch': {
                'name':
                'Test Logical Switch',
                'uri':
                LOGICAL_SWITCH_FROM_ONEVIEW['uri'],
                'logicalSwitchGroupUri':
                '/rest/logical-switch-groups/aa-bb-cc',
                'switchCredentialConfiguration': [{
                    'logicalSwitchManagementHost':
                    '172.16.1.3'
                }, {
                    'logicalSwitchManagementHost':
                    '172.16.1.4'
                }],
            },
            'logicalSwitchCredentials': []
        }
        self.resource.update.assert_called_once_with(data_for_update)
        self.resource.patch.assert_called_once_with(
            '/rest/logical-switches/f0d7ad37-2053-46ac-bb11-4ebdd079bb66',
            operation='replace',
            path='/scopeUris',
            value=['/rest/scopes/fake'])
Ejemplo n.º 14
0
    def test_should_not_update_scopes_when_same(self):
        LS_WITH_SCOPE = LOGICAL_SWITCH_FROM_ONEVIEW.copy()
        LS_WITH_SCOPE['scopeUris'] = ['/rest/birl']
        self.resource.get_by.side_effect = [[LS_WITH_SCOPE], []]
        self.resource.update.return_value = LS_WITH_SCOPE
        self.logical_switch_group_client.get_by.return_value = [{
            'uri':
            '/rest/logical-switch-groups/aa-bb-cc'
        }]

        self.mock_ansible_module.params = PARAMS_FOR_UPDATE_WITH_SWITCHES_AND_GROUPS
        self.resource.patch.return_value = LS_WITH_SCOPE

        LogicalSwitchModule().run()

        data_for_update = {
            'logicalSwitch': {
                'name':
                'Test Logical Switch',
                'uri':
                LS_WITH_SCOPE['uri'],
                'logicalSwitchGroupUri':
                '/rest/logical-switch-groups/aa-bb-cc',
                'switchCredentialConfiguration': [{
                    'logicalSwitchManagementHost':
                    '172.16.1.3'
                }, {
                    'logicalSwitchManagementHost':
                    '172.16.1.4'
                }],
            },
            'logicalSwitchCredentials': []
        }

        self.resource.update.assert_called_once_with(data_for_update)
        self.resource.patch.not_been_called()