def test_should_delete(self):
        self.resource.get_by.return_value = self.EXISTENT_UPLINK_SETS
        self.mock_ansible_module.params = deepcopy(self.PARAMS_FOR_ABSENT)

        UplinkSetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True, msg=UplinkSetModule.MSG_DELETED)
    def test_should_do_nothing_when_not_exist(self):
        self.resource.get_by.return_value = []
        self.mock_ansible_module.params = deepcopy(self.PARAMS_FOR_ABSENT)

        UplinkSetModule().run()

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

        UplinkSetModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=UplinkSetModule.MSG_KEY_REQUIRED)
    def test_should_fail_when_name_not_set(self):
        params = deepcopy(self.PARAMS_FOR_ABSENT)
        params['data'].pop('name')
        self.mock_ansible_module.params = params

        UplinkSetModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY, msg=UplinkSetModule.MSG_KEY_REQUIRED)
    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 = deepcopy(self.PARAMS_FOR_PRESENT)

        UplinkSetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=UplinkSetModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(uplink_set=self.UPLINK_SET_FOUND_BY_KEY))
    def test_should_replace_logical_interconnect_name_by_uri_on_absent_state(self):
        self.resource.get_by.return_value = EXISTENT_UPLINK_SETS
        self.mock_ov_client.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.mock_ansible_module.params = deepcopy(PARAMS_FOR_ABSENT_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.delete.assert_called_once_with(UPLINK_SET_FOUND_BY_KEY)
예제 #7
0
    def test_should_fail_when_logical_interconnect_uri_not_set(self):
        params = deepcopy(self.PARAMS_FOR_ABSENT)
        params['data'].pop('logicalInterconnectUri')
        self.mock_ansible_module.params = params

        UplinkSetModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=UplinkSetModule.MSG_KEY_REQUIRED
        )
    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 = deepcopy(self.PARAMS_FOR_PRESENT)

        UplinkSetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UplinkSetModule.MSG_CREATED,
            ansible_facts=dict(uplink_set=self.UPLINK_SET_FOUND_BY_KEY))
예제 #9
0
    def test_should_fail_when_logical_interconnect_not_found(self):
        self.resource.get_by_name.return_value = None
        self.mock_ov_client.logical_interconnects.get_by_name.return_value = None
        self.mock_ansible_module.params = deepcopy(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(exception=mock.ANY, msg=UplinkSetModule.MSG_LOGICAL_INTERCONNECT_NOT_FOUND)
    def test_rename_when_resource_exists(self):
        data_merged = UPLINK_SET_FOUND_BY_KEY.copy()
        data_merged['name'] = RENAMED_UPLINK_SET
        params_to_rename = deepcopy(PARAMS_TO_RENAME)
        self.resource.get_by = mock.MagicMock(side_effect=[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_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 = deepcopy(self.PARAMS_WITH_CHANGES)

        UplinkSetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UplinkSetModule.MSG_UPDATED,
            ansible_facts=dict(uplink_set=data_merged))
    def test_should_replace_logical_interconnect_name_by_uri(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = UPLINK_SET_FOUND_BY_KEY
        self.mock_ov_client.logical_interconnects.get_by_name.return_value = LOGICAL_INTERCONNECT
        self.mock_ansible_module.params = deepcopy(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(PARAMS_FOR_PRESENT['data'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UplinkSetModule.MSG_CREATED,
            ansible_facts=dict(uplink_set=UPLINK_SET_FOUND_BY_KEY)
        )
예제 #13
0
    def test_rename_when_resource_exists(self):
        data_merged = EXISTENT_UPLINK_SETS[0].copy()
        params = PARAMS_TO_RENAME["data"].copy()
        del params["newName"]
        data_merged.update(params)
        data_merged['name'] = RENAMED_UPLINK_SET

        params_to_rename = deepcopy(PARAMS_TO_RENAME)

        self.resource.data = EXISTENT_UPLINK_SETS[0]
        self.resource.get_by_name.return_value = self.resource

        obj = mock.Mock()
        obj.data = data_merged
        self.resource.update.return_value = obj

        self.mock_ansible_module.params = params_to_rename

        UplinkSetModule().run()

        self.resource.update.assert_called_once_with(data_merged)
예제 #14
0
    def test_should_replace_network_name_by_uri(self):
        self.resource.get_by_name.return_value = None
        obj = mock.Mock()
        obj.data = UPLINK_SETS
        self.resource.create.return_value = obj

        eth_obj = mock.Mock()
        eth_obj.data = ETHERNET
        self.mock_ov_client.ethernet_networks.get_by_name.return_value = eth_obj

        fc_obj = mock.Mock()
        fc_obj.data = FCNETWORK
        self.mock_ov_client.fc_networks.get_by_name.return_value = fc_obj

        fcoe_obj = mock.Mock()
        fcoe_obj.data = FCOENETWORK
        self.mock_ov_client.fcoe_networks.get_by_name.return_value = fcoe_obj

        self.mock_ansible_module.params = deepcopy(
            PARAMS_FOR_PRESENT_WITH_NETWORK_NAME)

        UplinkSetModule().run()

        self.mock_ov_client.ethernet_networks.get_by_name.assert_called_once_with(
            'EthernetNetwork')
        self.mock_ov_client.fc_networks.get_by_name.assert_called_once_with(
            'FcNetwork')
        self.mock_ov_client.fcoe_networks.get_by_name.assert_called_once_with(
            'FcoeNetwork')
        self.resource.create.assert_called_once_with(
            PARAMS_FOR_PRESENT_WITH_NETWORK['data'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=UplinkSetModule.MSG_CREATED,
            ansible_facts=dict(uplink_set=UPLINK_SETS))