Esempio n. 1
0
    def test_create_rename(self, fake_rename, fake_lookup_email_addr,
                           fake_create_machine_meta, fake_rmtree,
                           fake_make_ova, fake_makedirs,
                           fake_check_for_template, fake_as_completed,
                           fake_set_meta):
        """``templates`` - create makes the template directory unhidden when successful"""
        templates.create(self.username, self.template, self.machines,
                         self.portmaps, self.summary, self.logger)

        the_args, _ = fake_rename.call_args
        expected = ('/templates/.someTemplate', '/templates/someTemplate')

        self.assertEqual(the_args, expected)
Esempio n. 2
0
    def test_create(self, fake_rename, fake_lookup_email_addr,
                    fake_create_machine_meta, fake_rmtree, fake_make_ova,
                    fake_makedirs, fake_check_for_template, fake_as_completed,
                    fake_set_meta):
        """``templates`` - create returns None"""
        output = templates.create(self.username, self.template, self.machines,
                                  self.portmaps, self.summary, self.logger)

        self.assertTrue(output is None)
Esempio n. 3
0
 def test_create_template_exists(self, fake_rename, fake_lookup_email_addr,
                                 fake_create_machine_meta, fake_rmtree,
                                 fake_make_ova, fake_makedirs,
                                 fake_check_for_template, fake_as_completed,
                                 fake_set_meta):
     """``templates`` - create raises ValueError if the template already exists"""
     fake_check_for_template.side_effect = [FileExistsError('testing')]
     with self.assertRaises(ValueError):
         output = templates.create(self.username, self.template,
                                   self.machines, self.portmaps,
                                   self.summary, self.logger)
Esempio n. 4
0
def create_template(self, username, template, machines, portmaps, summary,
                    txn_id):
    """Make a new deployment template.

    :Returns: Dictionary

    :param username: The name of the account creating a deployment template.
    :type username: String

    :param template: What to name the new deployment template.
    :type template: String

    :param machines: The machines to include in the deployment template.
    :type machines: List

    :param portmaps: A mapping of machine IP to TCP port.
    :type portmaps: Dictionary

    :param summary:
    :type summary: String

    :param txn_id: A unique string supplied by the client to track the call through logs
    :type txn_id: String
    """
    logger = get_task_logger(txn_id=txn_id,
                             task_id=self.request.id,
                             loglevel=const.VLAB_DEPLOYMENT_LOG_LEVEL.upper())
    resp = {'content': {}, 'error': None, 'params': {}}
    logger.info('Task starting')
    try:
        templates.create(username, template, machines, portmaps, summary,
                         logger)
    except ValueError as doh:
        logger.error("Task failed")
        resp['error'] = '{}'.format(doh)
    else:
        logger.info("Task complete")
    return resp
Esempio n. 5
0
    def test_create_template_error(self, fake_rename, fake_lookup_email_addr,
                                   fake_create_machine_meta, fake_rmtree,
                                   fake_make_ova, fake_makedirs,
                                   fake_check_for_template, fake_as_completed,
                                   fake_set_meta):
        """``templates`` - create raises ValueError if unable to create the template"""
        fake_future = MagicMock()
        fake_future.result.return_value = [('', 'some error')]
        fake_as_completed.return_value = [fake_future]

        with self.assertRaises(ValueError):
            output = templates.create(self.username, self.template,
                                      self.machines, self.portmaps,
                                      self.summary, self.logger)
Esempio n. 6
0
    def test_create_template_exception(self, fake_rename,
                                       fake_lookup_email_addr,
                                       fake_create_machine_meta, fake_rmtree,
                                       fake_make_ova, fake_makedirs,
                                       fake_check_for_template,
                                       fake_as_completed, fake_set_meta):
        """``templates`` - create raises ValueError if template creation raises an exception"""
        fake_future = MagicMock()
        fake_future.result.side_effect = RuntimeError('testing')
        fake_as_completed.return_value = [fake_future]

        with self.assertRaises(ValueError):
            output = templates.create(self.username, self.template,
                                      self.machines, self.portmaps,
                                      self.summary, self.logger)
Esempio n. 7
0
    def test_create_template_fails_cleanup(
            self, fake_rename, fake_lookup_email_addr,
            fake_create_machine_meta, fake_rmtree, fake_make_ova,
            fake_makedirs, fake_check_for_template, fake_as_completed,
            fake_set_meta):
        """``templates`` - create deletes the partial template when unable to create the whole template"""
        fake_future = MagicMock()
        fake_future.result.side_effect = RuntimeError('testing')
        fake_as_completed.return_value = [fake_future]

        try:
            output = templates.create(self.username, self.template,
                                      self.machines, self.portmaps,
                                      self.summary, self.logger)
        except ValueError:
            pass

        self.assertTrue(fake_rmtree.called)