Exemple #1
0
    def test_import_keypair(self):
        key1_name = "new key pair"
        public_key = "ssh-rsa ABCDEFGHIJKLMNOPQR\r\n" \
                     "STUVWXYZ1234567890\r" \
                     "XXYYZZ user@computer\n\n"
        api.keypair_import(IsA(http.HttpRequest), key1_name,
                           public_key.replace("\r", "")
                                     .replace("\n", ""))
        self.mox.ReplayAll()

        formData = {'method': 'ImportKeypair',
                    'name': key1_name,
                    'public_key': public_key}
        url = reverse('horizon:project:access_and_security:keypairs:import')
        res = self.client.post(url, formData)
        self.assertMessageCount(res, success=1)
Exemple #2
0
    def test_import_keypair_invalid_key(self):
        key_name = "new key pair"
        public_key = "ABCDEF"

        self.mox.StubOutWithMock(api, 'keypair_import')
        api.keypair_import(IsA(http.HttpRequest), key_name, public_key) \
                        .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        formData = {'method': 'ImportKeypair',
                    'name': key_name,
                    'public_key': public_key}
        url = reverse('horizon:project:access_and_security:keypairs:import')
        res = self.client.post(url, formData, follow=True)
        self.assertEqual(res.redirect_chain, [])
        msg = 'Unable to import keypair.'
        self.assertFormErrors(res, count=1, message=msg)
Exemple #3
0
 def handle(self, request, data):
     try:
         # Remove any new lines in the public key
         data['public_key'] = NEW_LINES.sub("", data['public_key'])
         keypair = api.keypair_import(request,
                                      data['name'],
                                      data['public_key'])
         messages.success(request, _('Successfully imported public key: %s')
                                    % data['name'])
         return keypair
     except:
         exceptions.handle(request, ignore=True)
         self.api_error(_('Unable to import keypair.'))
         return False
Exemple #4
0
 def handle(self, request, data):
     try:
         # Remove any new lines in the public key
         data['public_key'] = NEW_LINES.sub("", data['public_key'])
         keypair = api.keypair_import(request,
                                      data['cloud'] + '-' + data['name'],
                                      data['public_key'])
         messages.success(
             request,
             _('Successfully imported public key: %s') % data['name'])
         return keypair
     except:
         exceptions.handle(request, ignore=True)
         self.api_error(_('Unable to import keypair.'))
         return False