Пример #1
0
 def test_import_boot_images_denied_if_not_admin(self):
     user = factory.make_user()
     client = OAuthAuthenticatedClient(user)
     response = client.post(
         reverse('nodegroups_handler'), {'op': 'import_boot_images'})
     self.assertEqual(
         httplib.FORBIDDEN, response.status_code,
         explain_unexpected_response(httplib.FORBIDDEN, response))
Пример #2
0
 def test_import_boot_images_denied_if_not_admin(self):
     user = factory.make_user()
     client = OAuthAuthenticatedClient(user)
     response = client.post(reverse('nodegroups_handler'),
                            {'op': 'import_boot_images'})
     self.assertEqual(
         httplib.FORBIDDEN, response.status_code,
         explain_unexpected_response(httplib.FORBIDDEN, response))
Пример #3
0
 def test_invalid_oauth_request(self):
     # An OAuth-signed request that does not validate is an error.
     user = factory.make_user()
     client = OAuthAuthenticatedClient(user)
     get_auth_tokens(user).delete()  # Delete the user's API keys.
     response = client.post(reverse('nodes_handler'), {'op': 'start'})
     observed = response.status_code, response.content
     expected = (
         Equals(httplib.UNAUTHORIZED),
         Contains("Invalid access token:"),
         )
     self.assertThat(observed, MatchesListwise(expected))
Пример #4
0
 def test_invalid_oauth_request(self):
     # An OAuth-signed request that does not validate is an error.
     user = factory.make_user()
     client = OAuthAuthenticatedClient(user)
     get_auth_tokens(user).delete()  # Delete the user's API keys.
     response = client.post(reverse('nodes_handler'), {'op': 'start'})
     observed = response.status_code, response.content
     expected = (
         Equals(httplib.UNAUTHORIZED),
         Contains("Invalid access token:"),
     )
     self.assertThat(observed, MatchesListwise(expected))
Пример #5
0
    def test_nodegroup_import_boot_images_calls_script(self):
        recorder = self.patch(tasks, 'call_and_check')
        proxy = factory.getRandomString()
        Config.objects.set_config('http_proxy', proxy)
        nodegroup = factory.make_node_group()
        admin = factory.make_admin()
        client = OAuthAuthenticatedClient(admin)

        response = client.post(
            reverse('nodegroup_handler', args=[nodegroup.uuid]),
            {'op': 'import_boot_images'})

        self.assertEqual(httplib.OK, response.status_code,
                         explain_unexpected_response(httplib.OK, response))
        recorder.assert_called_once_with(
            ['sudo', '-n', '-E', 'maas-import-pxe-files'], env=ANY)
Пример #6
0
    def test_nodegroup_import_boot_images_calls_script(self):
        recorder = self.patch(tasks, 'call_and_check')
        proxy = factory.getRandomString()
        Config.objects.set_config('http_proxy', proxy)
        nodegroup = factory.make_node_group()
        admin = factory.make_admin()
        client = OAuthAuthenticatedClient(admin)

        response = client.post(
            reverse('nodegroup_handler', args=[nodegroup.uuid]),
            {'op': 'import_boot_images'})

        self.assertEqual(
            httplib.OK, response.status_code,
            explain_unexpected_response(httplib.OK, response))
        recorder.assert_called_once_with(
            ['sudo', '-n', '-E', 'maas-import-pxe-files'], env=ANY)
Пример #7
0
    def test_details_allows_admin(self):
        nodegroup = factory.make_node_group()
        node = factory.make_node(nodegroup=nodegroup)
        user = factory.make_admin()
        client = OAuthAuthenticatedClient(user)

        response = client.post(
            reverse('nodegroup_handler', args=[nodegroup.uuid]),
            {'op': 'details', 'system_ids': [node.system_id]})

        self.assertEqual(httplib.OK, response.status_code)
        parsed_result = bson.BSON(response.content).decode()
        self.assertDictEqual(
            {
                node.system_id: {
                    "lshw": None,
                    "lldp": None,
                },
            },
            parsed_result)
Пример #8
0
    def test_details_allows_admin(self):
        nodegroup = factory.make_node_group()
        node = factory.make_node(nodegroup=nodegroup)
        user = factory.make_admin()
        client = OAuthAuthenticatedClient(user)

        response = client.post(
            reverse('nodegroup_handler', args=[nodegroup.uuid]), {
                'op': 'details',
                'system_ids': [node.system_id]
            })

        self.assertEqual(httplib.OK, response.status_code)
        parsed_result = bson.BSON(response.content).decode()
        self.assertDictEqual({
            node.system_id: {
                "lshw": None,
                "lldp": None,
            },
        }, parsed_result)
Пример #9
0
 def test_import_boot_images_calls_script_for_all_accepted_clusters(self):
     recorder = self.patch(nodegroup_module, 'import_boot_images')
     proxy = factory.make_name('proxy')
     Config.objects.set_config('http_proxy', proxy)
     accepted_nodegroups = [
         factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED),
         factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED),
     ]
     factory.make_node_group(status=NODEGROUP_STATUS.REJECTED)
     factory.make_node_group(status=NODEGROUP_STATUS.PENDING)
     admin = factory.make_admin()
     client = OAuthAuthenticatedClient(admin)
     response = client.post(
         reverse('nodegroups_handler'), {'op': 'import_boot_images'})
     self.assertEqual(
         httplib.OK, response.status_code,
         explain_unexpected_response(httplib.OK, response))
     queues = [
         kwargs['queue']
         for args, kwargs in recorder.apply_async.call_args_list]
     self.assertItemsEqual(
         [nodegroup.work_queue for nodegroup in accepted_nodegroups],
         queues)
Пример #10
0
 def test_import_boot_images_calls_script_for_all_accepted_clusters(self):
     recorder = self.patch(nodegroup_module, 'import_boot_images')
     proxy = factory.make_name('proxy')
     Config.objects.set_config('http_proxy', proxy)
     accepted_nodegroups = [
         factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED),
         factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED),
     ]
     factory.make_node_group(status=NODEGROUP_STATUS.REJECTED)
     factory.make_node_group(status=NODEGROUP_STATUS.PENDING)
     admin = factory.make_admin()
     client = OAuthAuthenticatedClient(admin)
     response = client.post(reverse('nodegroups_handler'),
                            {'op': 'import_boot_images'})
     self.assertEqual(httplib.OK, response.status_code,
                      explain_unexpected_response(httplib.OK, response))
     queues = [
         kwargs['queue']
         for args, kwargs in recorder.apply_async.call_args_list
     ]
     self.assertItemsEqual(
         [nodegroup.work_queue for nodegroup in accepted_nodegroups],
         queues)