Ejemplo n.º 1
0
 def test_populate_tags_task_routed_to_nodegroup_worker(self):
     nodegroup = factory.make_node_group()
     tag = factory.make_tag()
     task = self.patch(populate_tags_module, 'update_node_tags')
     populate_tags(tag)
     args, kwargs = task.apply_async.call_args
     self.assertEqual(nodegroup.work_queue, kwargs['queue'])
Ejemplo n.º 2
0
 def test_populate_tags_task_routed_to_nodegroup_worker(self):
     nodegroup = factory.make_node_group()
     tag = factory.make_tag()
     task = self.patch(populate_tags_module, 'update_node_tags')
     populate_tags(tag)
     args, kwargs = task.apply_async.call_args
     self.assertEqual(nodegroup.work_queue, kwargs['queue'])
Ejemplo n.º 3
0
 def populate_nodes(self):
     """Find all nodes that match this tag, and update them."""
     from maasserver.populate_tags import populate_tags
     if not self.definition:
         return
     # before we pass off any work, ensure the definition is valid XPATH
     try:
         etree.XPath(self.definition)
     except etree.XPathSyntaxError as e:
         msg = 'Invalid xpath expression: %s' % (e,)
         raise ValidationError({'definition': [msg]})
     # Now delete the existing tags
     self.node_set.clear()
     populate_tags(self)
Ejemplo n.º 4
0
 def populate_nodes(self):
     """Find all nodes that match this tag, and update them."""
     from maasserver.populate_tags import populate_tags
     if not self.is_defined:
         return
     # before we pass off any work, ensure the definition is valid XPATH
     try:
         etree.XPath(self.definition)
     except etree.XPathSyntaxError as e:
         msg = 'Invalid xpath expression: %s' % (e,)
         raise ValidationError({'definition': [msg]})
     # Now delete the existing tags
     self.node_set.clear()
     populate_tags(self)
Ejemplo n.º 5
0
 def test_populate_tags_task_routed_to_all_nodegroup_workers(self):
     nodegroups = [factory.make_node_group() for i in range(5)]
     tag = factory.make_tag()
     refresh = self.patch(populate_tags_module, 'refresh_worker')
     task = self.patch(populate_tags_module, 'update_node_tags')
     populate_tags(tag)
     refresh_calls = [mock.call(nodegroup) for nodegroup in nodegroups]
     refresh.assert_has_calls(refresh_calls, any_order=True)
     task_calls = [mock.call(queue=nodegroup.work_queue,
                            kwargs={
                              'tag_name': tag.name,
                              'tag_definition': tag.definition,
                              })
                  for nodegroup in nodegroups]
     task.apply_async.assert_has_calls(task_calls, any_order=True)
Ejemplo n.º 6
0
 def test_populate_tags_task_routed_to_all_nodegroup_workers(self):
     nodegroups = [factory.make_node_group() for i in range(5)]
     tag = factory.make_tag()
     refresh = self.patch(populate_tags_module, 'refresh_worker')
     task = self.patch(populate_tags_module, 'update_node_tags')
     populate_tags(tag)
     refresh_calls = [mock.call(nodegroup) for nodegroup in nodegroups]
     refresh.assert_has_calls(refresh_calls, any_order=True)
     task_calls = [
         mock.call(
             queue=nodegroup.work_queue,
             kwargs={
                 'tag_name': tag.name,
                 'tag_definition': tag.definition,
                 'tag_nsmap': tag_nsmap,
             },
         )
         for nodegroup in nodegroups
     ]
     task.apply_async.assert_has_calls(task_calls, any_order=True)
Ejemplo n.º 7
0
    def test_calls_are_made_to_all_clusters(self):
        rpc_fixture = self.prepare_live_rpc()
        rack_controllers = [factory.make_RackController() for _ in range(3)]
        protocols = []
        rack_creds = []
        for rack in rack_controllers:
            tokens = list(get_auth_tokens(rack.owner))
            if len(tokens) > 0:
                # Use the latest token.
                token = tokens[-1]
            else:
                token = create_auth_token(rack.owner)
            creds = convert_tuple_to_string(get_creds_tuple(token))
            rack_creds.append(creds)

            protocol = rpc_fixture.makeCluster(rack, EvaluateTag)
            protocol.EvaluateTag.side_effect = always_succeed_with({})
            protocols.append(protocol)
        tag = factory.make_Tag(populate=False)

        [d] = populate_tags(tag)

        # `d` is a testing-only convenience. We must wait for it to fire, and
        # we must do that from the reactor thread.
        wait_for_populate = asynchronous(lambda: d)
        wait_for_populate().wait(10)

        for rack, protocol, creds in zip(rack_controllers, protocols,
                                         rack_creds):
            self.expectThat(
                protocol.EvaluateTag,
                MockCalledOnceWith(
                    protocol,
                    tag_name=tag.name,
                    tag_definition=tag.definition,
                    system_id=rack.system_id,
                    tag_nsmap=ANY,
                    credentials=creds,
                    nodes=ANY,
                ),
            )