Ejemplo n.º 1
0
    def test_PUT_updates_power_type_default_rejects_params(self):
        # If one sets power_type to DEFAULT, on cannot set power_parameters.
        self.become_admin()
        power_parameters = factory.getRandomString()
        node = factory.make_node(
            owner=self.logged_in_user,
            power_type=POWER_TYPE.WAKE_ON_LAN,
            power_parameters=power_parameters)
        new_param = factory.getRandomString()
        response = self.client_put(
            self.get_node_uri(node),
            {
                'power_type': POWER_TYPE.DEFAULT,
                'power_parameters_address': new_param,
            })

        node = reload_object(node)
        self.assertEqual(
            (
                httplib.BAD_REQUEST,
                {'power_parameters': ["Unknown parameter(s): address."]}
            ),
            (response.status_code, json.loads(response.content)))
        self.assertEqual(
            power_parameters, reload_object(node).power_parameters)
Ejemplo n.º 2
0
 def test_data_values_override_defaults(self):
     key = factory.getRandomString()
     defaults = {key: factory.getRandomString()}
     data_value = factory.getRandomString()
     data = {key: data_value}
     results = get_overridden_query_dict(defaults, data)
     self.assertEqual([data_value], results.getlist(key))
Ejemplo n.º 3
0
 def test_EditUserForm_fails_validation_if_email_taken(self):
     another_email = '*****@*****.**' % factory.getRandomString()
     factory.make_user(email=another_email)
     email = '*****@*****.**' % factory.getRandomString()
     user = factory.make_user(email=email)
     form = EditUserForm(instance=user, data={'email': another_email})
     self.assertFormFailsValidationBecauseEmailNotUnique(form)
Ejemplo n.º 4
0
    def test_DictCharField_skip_check_false(self):
        # Create a value that will fail validation because it's too long.
        field_value = factory.getRandomString(10)
        field_name = factory.getRandomString()
        field_label = factory.getRandomString()
        # Force the check with multi_field_skip_check=false.
        data = QueryDict(
            'multi_field_%s=%s&multi_field_skip_check=false' % (
                field_name, field_value))

        class FakeFormSkip(forms.Form):
            multi_field = DictCharField(
                [(field_name, forms.CharField(
                    label=field_label, max_length=3))],
            skip_check=True)
        form = FakeFormSkip(data)

        self.assertFalse(form.is_valid())
        self.assertEqual(
            {
                'multi_field': [
                    "%s: Ensure this value has at most 3 characters "
                    "(it has 10)." % field_label]
            },
            form.errors)
Ejemplo n.º 5
0
 def test_load_preseed_template_generic_lookup(self):
     # The template lookup method ends up picking up a template named
     # 'generic' if no more specific template exist.
     content = self.create_template(self.location, GENERIC_FILENAME)
     node = factory.make_node(hostname=factory.getRandomString())
     template = load_preseed_template(node, factory.getRandomString())
     self.assertEqual(content, template.substitute())
Ejemplo n.º 6
0
    def test_DictCharField_processes_QueryDict_into_a_dict(self):
        class FakeForm(forms.Form):
            multi_field = DictCharField(
                [
                    ('field_a', forms.CharField(label='Field a')),
                    ('field_b', forms.CharField(
                        label='Field b', required=False, max_length=3)),
                    ('field_c', forms.CharField(
                        label='Field c', required=False)),
                ])

        fielda_value = factory.getRandomString()
        fieldc_value = factory.getRandomString()
        data = QueryDict(
            'multi_field_field_a=%s&multi_field_field_c=%s' % (
                fielda_value, fieldc_value))

        form = FakeForm(data)

        self.assertTrue(form.is_valid())
        self.assertEqual(
            {
                'field_a': fielda_value,
                'field_b': '',
                'field_c': fieldc_value,
            },
            form.cleaned_data['multi_field'])
Ejemplo n.º 7
0
 def test_start_commissioning_clears_node_commissioning_results(self):
     node = factory.make_node(status=NODE_STATUS.DECLARED)
     NodeCommissionResult.objects.store_data(
         node, factory.getRandomString(),
         random.randint(0, 10),
         factory.getRandomString())
     node.start_commissioning(factory.make_admin())
     self.assertItemsEqual([], node.nodecommissionresult_set.all())
Ejemplo n.º 8
0
 def test_hardware_updates_tags_match(self):
     tag1 = factory.make_tag(factory.getRandomString(10), "/node")
     tag2 = factory.make_tag(factory.getRandomString(10), "//node")
     node = factory.make_node()
     xmlbytes = '<node/>'
     node.set_hardware_details(xmlbytes)
     node = reload_object(node)
     self.assertEqual([tag1, tag2], list(node.tags.all()))
Ejemplo n.º 9
0
 def test_register_persistent_error_stores_last_error(self):
     error_message = factory.getRandomString()
     error_message2 = factory.getRandomString()
     component = get_random_component()
     register_persistent_error(component, error_message)
     register_persistent_error(component, error_message2)
     self.assertItemsEqual(
         [error_message2], get_persistent_errors())
Ejemplo n.º 10
0
 def test_DictCharWidget_id_for_label_uses_first_fields_name(self):
     names = [factory.getRandomString()]
     labels = [factory.getRandomString()]
     widget = DictCharWidget(
         [widgets.TextInput, widgets.TextInput], names, labels)
     self.assertEqual(
         ' _%s' % names[0],
         widget.id_for_label(' '))
Ejemplo n.º 11
0
 def test_connect_to_field_change_ignores_changes_to_other_fields(self):
     obj = FieldChangeTestModel(name2=factory.getRandomString())
     obj.save()
     callback = Mock()
     connect_to_field_change(callback, FieldChangeTestModel, 'name1')
     obj.name2 = factory.getRandomString()
     obj.save()
     self.assertEqual(0, callback.call_count)
Ejemplo n.º 12
0
 def test_clearcache_clears_specific_key(self):
     key = factory.getRandomString()
     cache.set(key, factory.getRandomString())
     another_key = factory.getRandomString()
     cache.set(another_key, factory.getRandomString())
     call_command('clearcache', key=key)
     self.assertIsNone(cache.get(key, None))
     self.assertIsNotNone(cache.get(another_key, None))
Ejemplo n.º 13
0
    def test_can_store_data(self):
        node = factory.make_node()
        name = factory.getRandomString(100)
        data = factory.getRandomString(1025)
        factory.make_node_commission_result(node=node, name=name, data=data)

        ncr = NodeCommissionResult.objects.get(name=name)
        self.assertAttributes(ncr, dict(node=node, data=data))
Ejemplo n.º 14
0
 def test_get_preseed_template_returns_None_if_no_template_locations(self):
     # get_preseed_template() returns None when no template locations are
     # defined.
     self.patch(settings, "PRESEED_TEMPLATE_LOCATIONS", [])
     self.assertEqual(
         (None, None),
         get_preseed_template(
             (factory.getRandomString(), factory.getRandomString())))
Ejemplo n.º 15
0
 def test_remove_None_values_removes_None_values_in_dict(self):
     random_input = factory.getRandomString()
     self.assertEqual(
         {random_input: random_input},
         remove_None_values({
             random_input: random_input,
             factory.getRandomString(): None
             }))
Ejemplo n.º 16
0
 def test_event_key(self):
     producer = FakeProducer()
     event_name = factory.getRandomString()
     obj = MessagesTestModel(name=factory.getRandomString())
     messenger = MAASMessenger(MessagesTestModel, producer)
     self.assertEqual(
         '%s.%s' % ('MessagesTestModel', event_name),
         messenger.event_key(event_name, obj))
Ejemplo n.º 17
0
 def test_get_effective_kernel_options_tag_overrides_global(self):
     node = factory.make_node()
     global_opts = factory.getRandomString()
     Config.objects.set_config('kernel_opts', global_opts)
     tag = factory.make_tag(kernel_opts=factory.getRandomString())
     node.tags.add(tag)
     self.assertEqual(
         (tag, tag.kernel_opts), node.get_effective_kernel_options())
Ejemplo n.º 18
0
 def test_get_abs_location_returns_rel_loc_if_static_root_not_none(self):
     static_root = factory.getRandomString()
     self.patch(settings, 'STATIC_ROOT', static_root)
     rel_location = os.path.join(
         factory.getRandomString(), factory.getRandomString())
     expected_location = os.path.join(static_root, rel_location)
     self.assertEqual(
         expected_location, get_absolute_location(location=rel_location))
Ejemplo n.º 19
0
    def test_logout(self):
        name = factory.getRandomString()
        password = factory.getRandomString()
        factory.make_user(name, password)
        self.client.login(username=name, password=password)
        self.client.post(reverse('logout'))

        self.assertNotIn('_auth_user_id', self.client.session)
Ejemplo n.º 20
0
 def test_get_abs_location_returns_rel_loc_if_static_root_is_none(self):
     self.patch(settings, 'STATIC_ROOT', None)
     rel_location = os.path.join(
         factory.getRandomString(), factory.getRandomString())
     rel_location_base = os.path.join(
         os.path.dirname(os.path.dirname(__file__)), 'static')
     expected_location = os.path.join(rel_location_base, rel_location)
     self.assertEqual(
         expected_location, get_absolute_location(location=rel_location))
Ejemplo n.º 21
0
 def test_get_preseed_filenames_if_node_is_None(self):
     release = factory.getRandomString()
     prefix = factory.getRandomString()
     self.assertSequenceEqual(
         [
             '%s_%s' % (prefix, release),
             '%s' % prefix,
         ],
         list(get_preseed_filenames(None, prefix, release)))
Ejemplo n.º 22
0
 def test_fqdn_returns_hostname_if_dns_not_managed(self):
     nodegroup = factory.make_node_group(
         name=factory.getRandomString(),
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
     hostname_with_domain = '%s.%s' % (
         factory.getRandomString(), factory.getRandomString())
     node = factory.make_node(
         nodegroup=nodegroup, hostname=hostname_with_domain)
     self.assertEqual(hostname_with_domain, node.fqdn)
Ejemplo n.º 23
0
 def test_POST_acquire_ignores_unknown_constraint(self):
     node = factory.make_node(status=NODE_STATUS.READY, owner=None)
     response = self.client.post(reverse('nodes_handler'), {
         'op': 'acquire',
         factory.getRandomString(): factory.getRandomString(),
     })
     self.assertEqual(httplib.OK, response.status_code)
     parsed_result = json.loads(response.content)
     self.assertEqual(node.system_id, parsed_result['system_id'])
Ejemplo n.º 24
0
 def test_createadmin_requires_email(self):
     username = factory.getRandomString()
     password = factory.getRandomString()
     error_text = assertCommandErrors(
         self, 'createadmin',
         username=username, password=password)
     self.assertIn(
         "You must provide an email with --email.",
         error_text)
Ejemplo n.º 25
0
    def test_login(self):
        name = factory.getRandomString()
        password = factory.getRandomString()
        user = self.make_user(name, password)
        response = self.client.post(
            reverse('login'), {'username': name, 'password': password})

        self.assertEqual(httplib.FOUND, response.status_code)
        self.assertEqual(user.id, self.client.session['_auth_user_id'])
Ejemplo n.º 26
0
    def test_manager_config_changed_connect_connects_by_config_name(self):
        recorder = CallRecorder()
        name = factory.getRandomString()
        value = factory.getRandomString()
        Config.objects.config_changed_connect(name, recorder)
        another_name = factory.getRandomString()
        Config.objects.set_config(another_name, value)

        self.assertEqual(0, len(recorder.calls))
Ejemplo n.º 27
0
    def test_login_failed(self):
        response = self.client.post(
            reverse('login'), {
                'username': factory.getRandomString(),
                'password': factory.getRandomString(),
                })

        self.assertEqual(httplib.OK, response.status_code)
        self.assertNotIn('_auth_user_id', self.client.session)
Ejemplo n.º 28
0
 def test_connect_to_field_change_calls_callback(self):
     callback = Mock()
     connect_to_field_change(callback, FieldChangeTestModel, 'name1')
     old_name1_value = factory.getRandomString()
     obj = FieldChangeTestModel(name1=old_name1_value)
     obj.save()
     obj.name1 = factory.getRandomString()
     obj.save()
     self.assertEqual((1, call(obj, old_name1_value, deleted=False)),
                      (callback.call_count, callback.call_args))
Ejemplo n.º 29
0
 def test_connect_to_field_change_calls_callback_for_each_real_save(self):
     callback = Mock()
     connect_to_field_change(callback, FieldChangeTestModel, 'name1')
     old_name1_value = factory.getRandomString()
     obj = FieldChangeTestModel(name1=old_name1_value)
     obj.save()
     obj.name1 = factory.getRandomString()
     obj.save()
     obj.save()
     self.assertEqual(1, callback.call_count)
Ejemplo n.º 30
0
 def test_inhibition_caches_inhibition(self):
     # The inhibition property will call inhibit() only once.  We can
     # prove this by changing the string inhibit() returns; it won't
     # affect the value of the property.
     inhibition = factory.getRandomString()
     action = FakeNodeAction(factory.make_node(), factory.make_user())
     action.fake_inhibition = inhibition
     self.assertEqual(inhibition, action.inhibition)
     action.fake_inhibition = factory.getRandomString()
     self.assertEqual(inhibition, action.inhibition)
Ejemplo n.º 31
0
    def test_manager_config_changed_connect_connects(self):
        recorder = CallRecorder()
        name = factory.getRandomString()
        value = factory.getRandomString()
        Config.objects.config_changed_connect(name, recorder)
        Config.objects.set_config(name, value)
        config = Config.objects.get(name=name)

        self.assertEqual(1, len(recorder.calls))
        self.assertEqual((Config, config, True), recorder.calls[0][0])
Ejemplo n.º 32
0
 def test_preseed_uses_configured_proxy(self):
     http_proxy = 'http://%s:%d/%s' % (
         factory.getRandomString(), factory.getRandomPort(),
         factory.getRandomString())
     Config.objects.set_config('http_proxy', http_proxy)
     expected_proxy_statement = (
         "mirror/http/proxy string %s" % http_proxy)
     preseed = render_preseed(
         factory.make_node(), PRESEED_TYPE.DEFAULT, "precise")
     self.assertIn(expected_proxy_statement, preseed)
Ejemplo n.º 33
0
    def test_manager_config_changed_connect_connects_multiple_same(self):
        # If the same method is connected twice, it will only get called
        # once.
        recorder = CallRecorder()
        name = factory.getRandomString()
        value = factory.getRandomString()
        Config.objects.config_changed_connect(name, recorder)
        Config.objects.config_changed_connect(name, recorder)
        Config.objects.set_config(name, value)

        self.assertEqual(1, len(recorder.calls))
Ejemplo n.º 34
0
    def test_PUT_updates_contents(self):
        old_content = b'old:%s' % factory.getRandomString().encode('ascii')
        script = factory.make_commissioning_script(content=old_content)
        new_content = b'new:%s' % factory.getRandomString().encode('ascii')

        response = self.client_put(
            self.get_url(script.name),
            {'content': factory.make_file_upload(content=new_content)})
        self.assertEqual(httplib.OK, response.status_code)

        self.assertEqual(new_content, reload_object(script).content)
Ejemplo n.º 35
0
 def test_get_preseed_filenames_supports_empty_prefix(self):
     hostname = factory.getRandomString()
     release = factory.getRandomString()
     node = factory.make_node(hostname=hostname)
     arch, subarch = node.architecture.split('/')
     self.assertSequenceEqual([
         '%s_%s_%s_%s' % (arch, subarch, release, hostname),
         '%s_%s_%s' % (arch, subarch, release),
         '%s_%s' % (arch, subarch),
         '%s' % arch,
     ], list(get_preseed_filenames(node, '', release)))
Ejemplo n.º 36
0
    def make_comment(self, length):
        """Create a comment of the desired length.

        The comment may contain spaces, but not begin or end in them.  It
        will be of the desired length both before and after stripping.
        """
        return ''.join([
            factory.getRandomString(1),
            factory.getRandomString(max([length - 2, 0]), spaces=True),
            factory.getRandomString(1),
            ])[:length]
Ejemplo n.º 37
0
    def test_login(self):
        name = factory.getRandomString()
        password = factory.getRandomString()
        user = self.make_user(name, password)
        response = self.client.post(reverse('login'), {
            'username': name,
            'password': password
        })

        self.assertEqual(httplib.FOUND, response.status_code)
        self.assertEqual(user.id, self.client.session['_auth_user_id'])
Ejemplo n.º 38
0
 def test_POST_new_refuses_non_admin(self):
     name = factory.getRandomString()
     response = self.client.post(
         reverse('tags_handler'), {
             'op': 'new',
             'name': name,
             'comment': factory.getRandomString(),
             'definition': factory.getRandomString(),
         })
     self.assertEqual(httplib.FORBIDDEN, response.status_code)
     self.assertFalse(Tag.objects.filter(name=name).exists())
Ejemplo n.º 39
0
    def test_manager_config_changed_connect_connects_multiple(self):
        recorder = CallRecorder()
        recorder2 = CallRecorder()
        name = factory.getRandomString()
        value = factory.getRandomString()
        Config.objects.config_changed_connect(name, recorder)
        Config.objects.config_changed_connect(name, recorder2)
        Config.objects.set_config(name, value)

        self.assertEqual(1, len(recorder.calls))
        self.assertEqual(1, len(recorder2.calls))
Ejemplo n.º 40
0
 def test_connect_to_field_change_calls_multiple_callbacks(self):
     callback1 = Mock()
     connect_to_field_change(callback1, FieldChangeTestModel, 'name1')
     callback2 = Mock()
     connect_to_field_change(callback2, FieldChangeTestModel, 'name1')
     old_name1_value = factory.getRandomString()
     obj = FieldChangeTestModel(name1=old_name1_value)
     obj.save()
     obj.name1 = factory.getRandomString()
     obj.save()
     self.assertEqual((1, 1), (callback1.call_count, callback2.call_count))
Ejemplo n.º 41
0
 def test_preseed_context_cluster_host_if_unmanaged(self):
     # If the nodegroup has no managed interface recorded, the cluster_host
     # context variable is still present and derived from the nodegroup.
     release = factory.getRandomString()
     nodegroup = factory.make_node_group(maas_url=factory.getRandomString())
     for interface in nodegroup.nodegroupinterface_set.all():
         interface.management = NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED
         interface.save()
     context = get_preseed_context(release, nodegroup)
     self.assertIsNotNone(context["cluster_host"])
     self.assertEqual(nodegroup.get_any_interface().ip,
                      context["cluster_host"])
Ejemplo n.º 42
0
 def test_signaling_stores_script_result(self):
     node = factory.make_node(status=NODE_STATUS.COMMISSIONING)
     client = make_node_client(node=node)
     script_result = random.randint(0, 10)
     filename = factory.getRandomString()
     response = call_signal(
         client,
         script_result=script_result,
         files={filename: factory.getRandomString().encode('ascii')})
     self.assertEqual(httplib.OK, response.status_code, response.content)
     result = NodeCommissionResult.objects.get(node=node)
     self.assertEqual(script_result, result.script_result)
Ejemplo n.º 43
0
    def test_PUT_ignores_unknown_fields(self):
        node = factory.make_node(
            owner=self.logged_in_user,
            after_commissioning_action=(
                NODE_AFTER_COMMISSIONING_ACTION.DEFAULT))
        field = factory.getRandomString()
        response = self.client_put(
            self.get_node_uri(node),
            {field: factory.getRandomString()}
            )

        self.assertEqual(httplib.OK, response.status_code)
Ejemplo n.º 44
0
 def test_signal_power_type_lower_case_works(self):
     node = factory.make_node(status=NODE_STATUS.COMMISSIONING)
     client = make_node_client(node=node)
     params = dict(power_address=factory.getRandomString(),
                   power_user=factory.getRandomString(),
                   power_pass=factory.getRandomString())
     response = call_signal(client,
                            power_type="ipmi",
                            power_parameters=json.dumps(params))
     self.assertEqual(httplib.OK, response.status_code, response.content)
     node = reload_object(node)
     self.assertEqual(params, node.power_parameters)
Ejemplo n.º 45
0
 def test_get_preseed_filenames_returns_list_with_default(self):
     # If default=True is passed to get_preseed_filenames, the
     # returned list will include the default template name as a
     # last resort template.
     hostname = factory.getRandomString()
     prefix = factory.getRandomString()
     release = factory.getRandomString()
     node = factory.make_node(hostname=hostname)
     self.assertSequenceEqual(
         prefix,
         list(get_preseed_filenames(node, prefix, release,
                                    default=False))[-1])
Ejemplo n.º 46
0
 def test_load_preseed_template_prefix_lookup(self):
     # 2nd last in the hierarchy is a template named 'prefix'.
     prefix = factory.getRandomString()
     # Create the generic template.  This one will be ignored due to the
     # presence of a more specific template.
     self.create_template(self.location, GENERIC_FILENAME)
     # Create the 'prefix' template.  This is the one which will be
     # picked up.
     content = self.create_template(self.location, prefix)
     node = factory.make_node(hostname=factory.getRandomString())
     template = load_preseed_template(node, prefix)
     self.assertEqual(content, template.substitute())
Ejemplo n.º 47
0
 def test_load_preseed_template_with_inherits(self):
     # A preseed file can "inherit" from another file.
     prefix = factory.getRandomString()
     # Create preseed template.
     master_template_name = factory.getRandomString()
     preseed_content = '{{inherit "%s"}}' % master_template_name
     self.create_template(self.location, prefix, preseed_content)
     master_content = self.create_template(self.location,
                                           master_template_name)
     node = factory.make_node()
     template = load_preseed_template(node, prefix)
     self.assertEqual(master_content, template.substitute())
Ejemplo n.º 48
0
 def test_create_msg(self):
     producer = FakeProducer()
     messenger = MAASMessenger(Node, producer)
     event_name = factory.getRandomString()
     obj_name = factory.getRandomString()
     obj = MessagesTestModel(name=obj_name)
     obj.save()
     msg = messenger.create_msg(event_name, obj)
     decoded_msg = json.loads(msg)
     self.assertItemsEqual(['instance', 'event_key'], list(decoded_msg))
     self.assertItemsEqual(['id', 'name'], list(decoded_msg['instance']))
     self.assertEqual(obj_name, decoded_msg['instance']['name'])
Ejemplo n.º 49
0
 def test_error_middleware_handles_ExternalComponentException(self):
     url = factory.getRandomString()
     request = fake_request(url, 'POST')
     error_message = factory.getRandomString()
     exception = ExternalComponentException(error_message)
     error_middleware = ErrorsMiddleware()
     response = error_middleware.process_exception(request, exception)
     # The response is a redirect.
     self.assertEqual(request.path, extract_redirect(response))
     # An error message has been published.
     self.assertEqual(
         [(constants.ERROR, error_message, '')], request._messages.messages)
Ejemplo n.º 50
0
    def test_publish_message_swallows_missing_rabbit(self):
        event = factory.getRandomString()
        instance = {factory.getRandomString(): factory.getRandomString()}

        def fail_for_lack_of_rabbit(*args, **kwargs):
            raise NoRabbit("I'm pretending not to have a RabbitMQ.")

        messenger = TestMessenger(MessagesTestModel, FakeProducer())
        messenger.producer.publish = fail_for_lack_of_rabbit

        messenger.publish_message(messenger.create_msg(event, instance))
        self.assertEqual([], messenger.producer.messages)
Ejemplo n.º 51
0
    def test_publish_message_propagates_exceptions(self):
        event = factory.getRandomString()
        instance = {factory.getRandomString(): factory.getRandomString()}

        def fail_despite_having_a_rabbit(*args, **kwargs):
            raise socket.error("I have a rabbit but I fail anyway.")

        messenger = TestMessenger(MessagesTestModel, FakeProducer())
        messenger.producer.publish = fail_despite_having_a_rabbit

        self.assertRaises(socket.error, messenger.publish_message,
                          messenger.create_msg(event, instance))
        self.assertEqual([], messenger.producer.messages)
Ejemplo n.º 52
0
 def test_get_preseed_filenames_returns_filenames(self):
     hostname = factory.getRandomString()
     prefix = factory.getRandomString()
     release = factory.getRandomString()
     node = factory.make_node(hostname=hostname)
     arch, subarch = node.architecture.split('/')
     self.assertSequenceEqual([
         '%s_%s_%s_%s_%s' % (prefix, arch, subarch, release, hostname),
         '%s_%s_%s_%s' % (prefix, arch, subarch, release),
         '%s_%s_%s' % (prefix, arch, subarch),
         '%s_%s' % (prefix, arch),
         '%s' % prefix,
         'generic',
     ], list(get_preseed_filenames(node, prefix, release, default=True)))
Ejemplo n.º 53
0
    def test_exchange_publish(self):
        exchange_name = factory.getRandomString()
        message_content = factory.getRandomString()
        exchange = RabbitExchange(RabbitSession(), exchange_name)
        self.addCleanup(exchange._session.disconnect)

        rabbitbase = RabbitBase(RabbitSession(), exchange_name)
        self.addCleanup(rabbitbase._session.disconnect)
        channel = rabbitbase.channel
        queue_name = channel.queue_declare(auto_delete=True)[0]
        channel.queue_bind(exchange=exchange_name, queue=queue_name)
        exchange.publish(message_content)
        message = self.basic_get(channel, queue_name, timeout=2)
        self.assertEqual(message_content, message.body)
Ejemplo n.º 54
0
 def test_get_effective_kernel_options_uses_first_real_tag_value(self):
     node = factory.make_node()
     # Intentionally create them in reverse order, so the default 'db' order
     # doesn't work, and we have asserted that we sort them.
     tag3 = factory.make_tag(factory.make_name('tag-03-'),
                             kernel_opts=factory.getRandomString())
     tag2 = factory.make_tag(factory.make_name('tag-02-'),
                             kernel_opts=factory.getRandomString())
     tag1 = factory.make_tag(factory.make_name('tag-01-'), kernel_opts=None)
     self.assertTrue(tag1.name < tag2.name)
     self.assertTrue(tag2.name < tag3.name)
     node.tags.add(tag1, tag2, tag3)
     self.assertEqual(
         (tag2, tag2.kernel_opts), node.get_effective_kernel_options())
Ejemplo n.º 55
0
 def test_load_preseed_template_parent_lookup_doesnt_include_default(self):
     # The lookup for parent templates does not include the default
     # 'generic' file.
     prefix = factory.getRandomString()
     # Create 'generic' template.  It won't be used because the
     # lookup for parent templates does not use the 'generic' template.
     self.create_template(self.location, GENERIC_FILENAME)
     unknown_master_template_name = factory.getRandomString()
     # Create preseed template.
     preseed_content = '{{inherit "%s"}}' % unknown_master_template_name
     self.create_template(self.location, prefix, preseed_content)
     node = factory.make_node()
     template = load_preseed_template(node, prefix)
     self.assertRaises(TemplateNotFoundError, template.substitute)
Ejemplo n.º 56
0
    def test_add_user_POST(self):
        params = {
            'username': factory.getRandomString(),
            'last_name': factory.getRandomString(30),
            'email': factory.getRandomEmail(),
            'is_superuser': factory.getRandomBoolean(),
        }
        password = factory.getRandomString()
        params.update(make_password_params(password))

        response = self.client.post(reverse('accounts-add'), params)
        self.assertEqual(httplib.FOUND, response.status_code)
        user = User.objects.get(username=params['username'])
        self.assertAttributes(user, subset_dict(params, user_attributes))
        self.assertTrue(user.check_password(password))
Ejemplo n.º 57
0
    def test_rabbit_queue_binds_queue(self):
        exchange_name = factory.getRandomString()
        message_content = factory.getRandomString()
        queue = RabbitQueue(RabbitSession(), exchange_name)
        self.addCleanup(queue._session.disconnect)

        # Publish to queue.name.
        base = RabbitBase(RabbitSession(), exchange_name)
        self.addCleanup(base._session.disconnect)
        channel = base.channel
        msg = amqp.Message(message_content)
        channel.basic_publish(
            exchange=exchange_name, routing_key='', msg=msg)
        message = channel.basic_get(queue.name)
        self.assertEqual(message_content, message.body)
Ejemplo n.º 58
0
 def test_POST_new_without_definition_creates_tag(self):
     self.become_admin()
     name = factory.getRandomString()
     comment = factory.getRandomString()
     response = self.client.post(reverse('tags_handler'), {
         'op': 'new',
         'name': name,
         'comment': comment,
     })
     self.assertEqual(httplib.OK, response.status_code)
     parsed_result = json.loads(response.content)
     self.assertEqual(name, parsed_result['name'])
     self.assertEqual(comment, parsed_result['comment'])
     self.assertEqual("", parsed_result['definition'])
     self.assertTrue(Tag.objects.filter(name=name).exists())
Ejemplo n.º 59
0
 def test_signaling_commissioning_failure_sets_node_error(self):
     node = factory.make_node(status=NODE_STATUS.COMMISSIONING)
     client = make_node_client(node=node)
     error_text = factory.getRandomString()
     response = call_signal(client, status='FAILED', error=error_text)
     self.assertEqual(httplib.OK, response.status_code)
     self.assertEqual(error_text, reload_object(node).error)
Ejemplo n.º 60
0
 def test_signaling_no_error_clears_existing_error(self):
     node = factory.make_node(status=NODE_STATUS.COMMISSIONING,
                              error=factory.getRandomString())
     client = make_node_client(node=node)
     response = call_signal(client)
     self.assertEqual(httplib.OK, response.status_code)
     self.assertEqual('', reload_object(node).error)