def test_build_image_indirection(self):
        """Test _build_image_indirection function"""
        expected = "Created task: %d" % self.task_id + "\n"
        expected += "Task info: %s/taskinfo?taskID=%s" % (self.weburl, self.task_id) + "\n"

        with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
            _build_image_indirection(
                self.options, self.task_opts, self.session, [])
        self.assert_console_message(stdout, expected)
Exemplo n.º 2
0
    def test_build_image_indirection(self):
        """Test _build_image_indirection function"""
        expected = "Created task: %d" % self.task_id + "\n"
        expected += "Task info: %s/taskinfo?taskID=%s" % (self.weburl,
                                                          self.task_id) + "\n"

        with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
            _build_image_indirection(self.options, self.task_opts,
                                     self.session, [])
        self.assert_console_message(stdout, expected)
    def test_build_image_indirection_with_noprogress(self):
        """Test _build_image_indirection function with noprogress option"""
        expected = "\n"
        expected += "Created task: %d" % self.task_id + "\n"
        expected += "Task info: %s/taskinfo?taskID=%s" % (self.weburl, self.task_id) + "\n"

        self.task_opts.indirection_template_url = None
        self.task_opts.scratch = True
        self.task_opts.noprogress = True
        with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
            _build_image_indirection(
                self.options, self.task_opts, self.session, [])
        self.assert_console_message(stdout, expected)
        args, kwargs = self.session.uploadWrapper.call_args
        self.assertEqual(kwargs['callback'], None)
Exemplo n.º 4
0
    def test_build_image_indirection_with_noprogress(self):
        """Test _build_image_indirection function with noprogress option"""
        expected = "\n"
        expected += "Created task: %d" % self.task_id + "\n"
        expected += "Task info: %s/taskinfo?taskID=%s" % (self.weburl,
                                                          self.task_id) + "\n"

        self.task_opts.indirection_template_url = None
        self.task_opts.scratch = True
        self.task_opts.noprogress = True
        with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
            _build_image_indirection(self.options, self.task_opts,
                                     self.session, [])
        self.assert_console_message(stdout, expected)
        args, kwargs = self.session.uploadWrapper.call_args
        self.assertEqual(kwargs['callback'], None)
Exemplo n.º 5
0
    def test_build_image_indirection_expections(self):
        """Test _build_image_indirection all exceptions"""

        # Case 1. sanity check for utility image options
        self.task_opts.utility_image_task = None
        self.task_opts.utility_image_build = None
        expected = "You must specify either a utility-image task or build ID/NVR"
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(self.options, self.task_opts,
                                     self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_not_called()

        # Case 2. sanity check for base image options
        self.task_opts.utility_image_build = 'image-utils-26.1'
        self.task_opts.base_image_task = None
        self.task_opts.base_image_build = None
        expected = "You must specify either a base-image task or build ID/NVR"
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(self.options, self.task_opts,
                                     self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_not_called()

        self.task_opts.base_image_build = 'image-base-26.1'

        # Case 3. missing required options
        required = [
            'name', 'version', 'arch', 'target', 'indirection_template',
            'results_loc'
        ]
        for r in required:
            orig = getattr(self.task_opts, r)
            setattr(self.task_opts, r, None)
            expected = "Missing the following required options: "
            expected += "--" + r.replace('_', '-') + "\n"
            with self.assertRaises(koji.GenericError) as cm, \
                    mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
                _build_image_indirection(self.options, self.task_opts,
                                         self.session, [])
            self.assert_console_message(stdout, expected)
            self.assertEqual(str(cm.exception),
                             "Missing required options specified above")
            self.activate_session.assert_not_called()
            setattr(self.task_opts, r, orig)

        # Case 4. target not found error
        self.session.getBuildTarget.return_value = {}
        expected = "Unknown build target: %s" % {}
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(self.options, self.task_opts,
                                     self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_called_with(self.session, self.options)

        # Case 5. tag not found error
        self.session.getBuildTarget.return_value = self.build_target
        self.session.getTag.return_value = {}
        expected = "Unknown destination tag: %s" % self.build_target[
            'dest_tag_name']
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(self.options, self.task_opts,
                                     self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_called_with(self.session, self.options)

        # Case 6. --indirection-template-url is not given and --scatch is not set
        self.session.getTag.return_value = self.dest_tag
        self.task_opts.indirection_template_url = None
        self.task_opts.scratch = None
        expected = "Non-scratch builds must provide a URL for the indirection template"
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(self.options, self.task_opts,
                                     self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_called_with(self.session, self.options)
    def test_build_image_indirection_expections(self):
        """Test _build_image_indirection all exceptions"""

        # Case 1. sanity check for utility image options
        self.task_opts.utility_image_task = None
        self.task_opts.utility_image_build = None
        expected = "You must specify either a utility-image task or build ID/NVR"
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(
                self.options, self.task_opts, self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_not_called()

        # Case 2. sanity check for base image options
        self.task_opts.utility_image_build = 'image-utils-26.1'
        self.task_opts.base_image_task = None
        self.task_opts.base_image_build = None
        expected = "You must specify either a base-image task or build ID/NVR"
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(
                self.options, self.task_opts, self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_not_called()

        self.task_opts.base_image_build = 'image-base-26.1'

        # Case 3. missing required options
        required = ['name', 'version', 'arch', 'target',
                    'indirection_template', 'results_loc']
        for r in required:
            orig = getattr(self.task_opts, r)
            setattr(self.task_opts, r, None)
            expected = "Missing the following required options: "
            expected += "--" + r.replace('_', '-') + "\n"
            with self.assertRaises(koji.GenericError) as cm:
                with  mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
                    _build_image_indirection(
                        self.options, self.task_opts, self.session, [])
            self.assert_console_message(stdout, expected)
            self.assertEqual(
                str(cm.exception), "Missing required options specified above")
            self.activate_session.assert_not_called()
            setattr(self.task_opts, r, orig)

        # Case 4. target not found error
        self.session.getBuildTarget.return_value = {}
        expected = "Unknown build target: %s" % {}
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(
                self.options, self.task_opts, self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_called_with(self.session, self.options)

        # Case 5. tag not found error
        self.session.getBuildTarget.return_value = self.build_target
        self.session.getTag.return_value = {}
        expected = "Unknown destination tag: %s" % self.build_target['dest_tag_name']
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(
                self.options, self.task_opts, self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_called_with(self.session, self.options)

        # Case 6. --indirection-template-url is not given and --scatch is not set
        self.session.getTag.return_value = self.dest_tag
        self.task_opts.indirection_template_url = None
        self.task_opts.scratch = None
        expected = "Non-scratch builds must provide a URL for the indirection template"
        with self.assertRaises(koji.GenericError) as cm:
            _build_image_indirection(
                self.options, self.task_opts, self.session, [])
        self.assertEqual(str(cm.exception), expected)
        self.activate_session.assert_called_with(self.session, self.options)