Exemplo n.º 1
0
    def test_golden_image_archive_download_nonexistent(self):
        self.resource.get_by.return_value = []
        self.mock_ansible_module.params = self.GOLDEN_IMAGE_ARCHIVE_DOWNLOAD

        GoldenImageModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=GoldenImageModule.MSG_WAS_NOT_FOUND)
Exemplo n.º 2
0
    def test_should_fail_when_build_plan_not_found(self):
        self.resource.get_by.return_value = []
        self.mock_ov_client.build_plans.get_by.return_value = None

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_CREATE

        GoldenImageModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=GoldenImageModule.MSG_BUILD_PLAN_WAS_NOT_FOUND)
Exemplo n.º 3
0
    def test_should_fail_when_os_volume_not_found(self):
        self.resource.get_by.return_value = []

        self.mock_ov_client.os_volumes.get_by_name.return_value = None

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_CREATE

        GoldenImageModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=GoldenImageModule.MSG_OS_VOLUME_WAS_NOT_FOUND)
Exemplo n.º 4
0
    def test_should_fail_when_mandatory_attributes_are_missing(self):
        self.resource.get_by.return_value = []

        del self.GOLDEN_IMAGE_CREATE['data']['osVolumeName']

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_CREATE

        GoldenImageModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=GoldenImageModule.MSG_MISSING_MANDATORY_ATTRIBUTES)
Exemplo n.º 5
0
    def test_should_fail_when_present_is_incosistent(self):
        self.resource.get_by.return_value = []
        self.mock_ov_client.os_volumes.get_by_name.return_value = {'uri': '/rest/os-volumes/1'}

        self.GOLDEN_IMAGE_CREATE['data']['localImageFilePath'] = 'filename'

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_CREATE

        GoldenImageModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=GoldenImageModule.MSG_CANT_CREATE_AND_UPLOAD)
Exemplo n.º 6
0
    def test_should_do_nothing_when_deleting_a_non_existent_golden_image(self):
        self.resource.get_by.return_value = []

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_DELETE

        GoldenImageModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=GoldenImageModule.MSG_ALREADY_ABSENT
        )
Exemplo n.º 7
0
    def test_delete_golden_image(self):
        self.resource.get_by.return_value = [self.GOLDEN_IMAGE_CREATE['data']]

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_DELETE

        GoldenImageModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=GoldenImageModule.MSG_DELETED
        )
Exemplo n.º 8
0
    def test_update_golden_image(self):
        self.resource.get_by.return_value = [self.GOLDEN_IMAGE_CREATE['data']]
        self.resource.update.return_value = {"name": "name"}

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_UPDATE

        GoldenImageModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=GoldenImageModule.MSG_UPDATED,
            ansible_facts=dict(golden_image={"name": "name"})
        )
Exemplo n.º 9
0
    def test_should_not_update_when_data_is_equals(self):
        self.resource.get_by.return_value = [self.GOLDEN_IMAGE_UPDATE['data']]

        del self.GOLDEN_IMAGE_UPDATE['data']['newName']

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_UPDATE

        GoldenImageModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=GoldenImageModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(golden_image=self.GOLDEN_IMAGE_UPDATE['data'])
        )
Exemplo n.º 10
0
    def test_golden_image_archive_download(self):
        golden_image = self.GOLDEN_IMAGE_CREATE['data']
        golden_image['uri'] = '/rest/golden-images/1'

        self.resource.get_by.return_value = [golden_image]
        self.mock_ansible_module.params = self.GOLDEN_IMAGE_ARCHIVE_DOWNLOAD

        GoldenImageModule().run()

        download_file = self.GOLDEN_IMAGE_ARCHIVE_DOWNLOAD['data']['destination_file_path']
        self.resource.download_archive.assert_called_once_with('/rest/golden-images/1', download_file)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=GoldenImageModule.MSG_ARCHIVE_DOWNLOADED,
            ansible_facts={})
Exemplo n.º 11
0
    def test_upload_a_golden_image(self):
        self.resource.get_by.return_value = []
        self.resource.upload.return_value = {"name": "name"}

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_UPLOAD

        file_path = self.GOLDEN_IMAGE_UPLOAD['data']['localImageFilePath']

        GoldenImageModule().run()

        self.resource.upload.assert_called_once_with(
            file_path,
            self.GOLDEN_IMAGE_UPLOAD['data'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=GoldenImageModule.MSG_UPLOADED,
            ansible_facts=dict(golden_image={"name": "name"})
        )
Exemplo n.º 12
0
    def test_create_new_golden_image(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = {"name": "name"}
        self.mock_ov_client.os_volumes.get_by_name.return_value = {'uri': '/rest/os-volumes/1'}
        self.mock_ov_client.build_plans.get_by.return_value = [{'uri': '/rest/build-plans/1'}]

        self.mock_ansible_module.params = self.GOLDEN_IMAGE_CREATE

        GoldenImageModule().run()

        self.resource.create.assert_called_once_with(
            {'osVolumeURI': '/rest/os-volumes/1',
             'description': 'Test Description',
             'buildPlanUri': '/rest/build-plans/1',
             'name': 'Demo Golden Image creation',
             'imageCapture': 'true'})

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=GoldenImageModule.MSG_CREATED,
            ansible_facts=dict(golden_image={"name": "name"})
        )