Beispiel #1
0
 def make_boot_resources_create_action(self):
     self.stdio = self.useFixture(CaptureStandardIO())
     action_bases = (BootResourcesCreateAction,)
     action_ns = {
         "action": {"method": "POST"},
         "handler": {"uri": b"/MAAS/api/2.0/boot-resources/", "params": []},
         "profile": {"credentials": make_api_credentials()},
     }
     action_class = type("create", action_bases, action_ns)
     action = action_class(Mock())
     return action
Beispiel #2
0
 def make_sshkeys_import_action(self):
     self.stdio = self.useFixture(CaptureStandardIO())
     action_bases = (SSHKeysImportAction,)
     action_ns = {
         "action": {"method": "POST"},
         "handler": {"uri": b"/MAAS/api/2.0/sshkeys/", "params": []},
         "profile": {"credentials": make_api_credentials()},
     }
     action_class = type("import", action_bases, action_ns)
     action = action_class(Mock())
     return action
Beispiel #3
0
    def test_sends_boot_images_to_server(self):
        self.useFixture(ConfigFixture({'tftp': {'root': self.make_dir()}}))
        self.set_maas_url()
        auth.record_api_credentials(':'.join(make_api_credentials()))
        image = make_boot_image_params()
        self.patch(tftppath, 'list_boot_images', Mock(return_value=[image]))
        self.patch(boot_images, "get_cluster_uuid")
        self.patch(MAASClient, 'post')

        report_boot_images.delay()

        args, kwargs = MAASClient.post.call_args
        self.assertItemsEqual([image], json.loads(kwargs['images']))
Beispiel #4
0
    def test_sends_boot_images_to_server(self):
        self.useFixture(ConfigFixture({'tftp': {'root': self.make_dir()}}))
        self.set_maas_url()
        auth.record_api_credentials(':'.join(make_api_credentials()))
        image = make_boot_image_params()
        self.patch(tftppath, 'list_boot_images', Mock(return_value=[image]))
        self.patch(boot_images, "get_cluster_uuid")
        self.patch(MAASClient, 'post')

        report_boot_images.delay()

        args, kwargs = MAASClient.post.call_args
        self.assertItemsEqual([image], json.loads(kwargs['images']))
Beispiel #5
0
    def setUp(self):
        # Initialise the knowledge cache.
        super(TestPeriodicTask, self).setUp()
        uuid = factory.getRandomUUID()
        maas_url = 'http://%s.example.com/%s/' % (
            factory.make_name('host'),
            factory.getRandomString(),
        )
        api_credentials = make_api_credentials()

        cache.cache.set(NODEGROUP_UUID_CACHE_KEY, uuid)
        os.environ["MAAS_URL"] = maas_url
        cache.cache.set('api_credentials', ':'.join(api_credentials))

        self.knowledge = dict(nodegroup_uuid=uuid,
                              api_credentials=api_credentials,
                              maas_url=maas_url)
 def make_boot_resources_create_action(self):
     self.stdio = self.useFixture(CaptureStandardIO())
     action_bases = (BootResourcesCreateAction, )
     action_ns = {
         "action": {
             'method': 'POST'
         },
         "handler": {
             'uri': b'/MAAS/api/2.0/boot-resources/',
             'params': []
         },
         "profile": {
             'credentials': make_api_credentials()
         }
     }
     action_class = type("create", action_bases, action_ns)
     action = action_class(Mock())
     return action
Beispiel #7
0
 def test_updates_api_credentials(self):
     credentials = make_api_credentials()
     refresh_secrets(
         api_credentials=convert_tuple_to_string(credentials))
     self.assertEqual(credentials, auth.get_recorded_api_credentials())
Beispiel #8
0
 def set_api_credentials(self):
     record_api_credentials(':'.join(make_api_credentials()))
Beispiel #9
0
 def set_api_credentials(self):
     record_api_credentials(':'.join(make_api_credentials()))
Beispiel #10
0
 def test_updates_api_credentials(self):
     credentials = make_api_credentials()
     refresh_secrets(api_credentials=convert_tuple_to_string(credentials))
     self.assertEqual(credentials, auth.get_recorded_api_credentials())
Beispiel #11
0
 def test_get_recorded_api_credentials_returns_credentials_as_tuple(self):
     creds = make_api_credentials()
     auth.record_api_credentials(convert_tuple_to_string(creds))
     self.assertEqual(creds, auth.get_recorded_api_credentials())
Beispiel #12
0
 def test_record_api_credentials_records_credentials_string(self):
     creds_string = convert_tuple_to_string(make_api_credentials())
     auth.record_api_credentials(creds_string)
     self.assertEqual(creds_string,
                      cache.cache.get(auth.API_CREDENTIALS_CACHE_KEY))
Beispiel #13
0
 def test_get_recorded_api_credentials_returns_credentials_as_tuple(self):
     creds = make_api_credentials()
     auth.record_api_credentials(convert_tuple_to_string(creds))
     self.assertEqual(creds, auth.get_recorded_api_credentials())
Beispiel #14
0
 def test_record_api_credentials_records_credentials_string(self):
     creds_string = convert_tuple_to_string(make_api_credentials())
     auth.record_api_credentials(creds_string)
     self.assertEqual(
         creds_string, cache.cache.get(auth.API_CREDENTIALS_CACHE_KEY))