Ejemplo n.º 1
0
    def test_empty(self):
        res = utils.format_node_name(None, None, 0)
        self.assertIsNotNone(res)
        self.assertEqual(13, len(res))

        res = utils.format_node_name("", None, 0)
        self.assertIsNotNone(res)
        self.assertEqual(13, len(res))
Ejemplo n.º 2
0
    def test_has_both(self):
        res = utils.format_node_name("prefix-$3R-$I", None, 12)
        self.assertEqual(13, len(res))

        res = utils.format_node_name("$3R-prefix-$5I", None, 12)
        self.assertEqual(16, len(res))
Ejemplo n.º 3
0
    def test_has_index(self):
        res = utils.format_node_name("prefix-$I", None, 12)
        self.assertEqual(9, len(res))

        res = utils.format_node_name("prefix-$5I", None, 12)
        self.assertEqual(12, len(res))
Ejemplo n.º 4
0
    def test_has_random(self):
        res = utils.format_node_name("prefix-$R", None, 0)
        self.assertEqual(15, len(res))

        res = utils.format_node_name("prefix-$5R", None, 0)
        self.assertEqual(12, len(res))
Ejemplo n.º 5
0
    def _create_nodes(self, count):
        """Utility method for node creation.

        :param count: Number of nodes to create.
        :returns: A tuple comprised of the result and reason.
        """

        if count == 0:
            return self.RES_OK, ''

        placement = self.data.get('placement', None)

        nodes = []
        child = []
        # conunt >= 1
        for m in range(count):
            index = co.Cluster.get_next_index(self.context, self.entity.id)
            kwargs = {
                'index': index,
                'metadata': {},
                'user': self.entity.user,
                'project': self.entity.project,
                'domain': self.entity.domain,
            }
            if placement is not None:
                # We assume placement is a list
                kwargs['data'] = {'placement': placement['placements'][m]}

            name_format = self.entity.config.get("node.name.format", "")
            name = utils.format_node_name(name_format, self.entity, index)
            node = node_mod.Node(name,
                                 self.entity.profile_id,
                                 self.entity.id,
                                 context=self.context,
                                 **kwargs)

            node.store(self.context)
            nodes.append(node)

            kwargs = {
                'name': 'node_create_%s' % node.id[:8],
                'cause': consts.CAUSE_DERIVED,
            }
            action_id = base.Action.create(self.context, node.id,
                                           consts.NODE_CREATE, **kwargs)
            child.append(action_id)

        # Build dependency and make the new action ready
        dobj.Dependency.create(self.context, [a for a in child], self.id)
        for cid in child:
            ao.Action.update(self.context, cid, {'status': base.Action.READY})
        dispatcher.start_action()

        # Wait for cluster creation to complete
        res, reason = self._wait_for_dependents()
        if res == self.RES_OK:
            nodes_added = [n.id for n in nodes]
            self.outputs['nodes_added'] = nodes_added
            creation = self.data.get('creation', {})
            creation['nodes'] = nodes_added
            self.data['creation'] = creation
            for node in nodes:
                self.entity.add_node(node)
        else:
            reason = 'Failed in creating nodes.'

        return res, reason