Example #1
0
    def test_cs_get_ip(self):
        stack_name = 'test_cs_get_ip_err'
        (t, stack) = self._setup_test_stack(stack_name)
        cs = cloud_server.CloudServer('cs_create_image_err',
                                      t['Resources']['WebServer'], stack)
        cs.addresses = {
            'public': [{
                'version': 4,
                'addr': '4.5.6.7'
            }, {
                'version': 6,
                'addr': 'fake:ip::6'
            }],
            'private': [{
                'version': 4,
                'addr': '10.13.12.13'
            }]
        }
        self.mock_get_ip(cs)
        self.assertEqual(cs.public_ip, '4.5.6.7')
        self.mock_get_ip(cs)
        self.assertEqual(cs.private_ip, '10.13.12.13')

        cs.addresses = {'public': [], 'private': []}
        self.mock_get_ip(cs)
        self.assertRaises(exception.Error, cs._get_ip, 'public')
Example #2
0
    def _setup_test_cs(self, return_server, name):
        stack_name = '%s_stack' % name
        (t, stack) = self._setup_test_stack(stack_name)

        cs_name = 'Fedora 17 (Beefy Miracle)'
        t['Resources']['WebServer']['Properties']['image'] = '1'
        t['Resources']['WebServer']['Properties']['flavor'] = '2'

        cs = cloud_server.CloudServer('%s_name' % name,
                                      t['Resources']['WebServer'], stack)
        cs._private_key = rsa_key
        cs.t = cs.stack.resolve_runtime_data(cs.t)

        flavor = t['Resources']['WebServer']['Properties']['flavor']

        self.m.StubOutWithMock(self.fc.servers, 'create')
        self.fc.servers.create(utils.PhysName(stack_name, cs.name),
                               "1",
                               flavor,
                               files=mox.IgnoreArg()).AndReturn(return_server)
        return_server.adminPass = "******"

        self.m.StubOutWithMock(cloud_server.CloudServer, 'script')
        cloud_server.CloudServer.script = "foobar"

        self.m.StubOutWithMock(rackspace_resource.RackspaceResource, "nova")
        rackspace_resource.RackspaceResource.nova().MultipleTimes()\
                                                   .AndReturn(self.fc)

        self._mock_ssh_sftp()
        return cs
Example #3
0
    def test_private_key(self):
        stack_name = 'test_private_key'
        (t, stack) = self._setup_test_stack(stack_name)
        cs = cloud_server.CloudServer('cs_private_key',
                                      t['Resources']['WebServer'], stack)

        # This gives the fake cloud server an id and created_time attribute
        cs._store_or_update(cs.CREATE, cs.IN_PROGRESS, 'test_store')

        cs.private_key = 'fake private key'
        rs = db_api.resource_get_by_name_and_stack(None, 'cs_private_key',
                                                   stack.id)
        encrypted_key = rs.data[0]['value']
        self.assertNotEqual(encrypted_key, "fake private key")
        decrypted_key = cs.private_key
        self.assertEqual(decrypted_key, "fake private key")
Example #4
0
    def test_cs_create_image_name_okay(self):
        stack_name = 'test_cs_create_image_name_err_stack'
        (t, stack) = self._setup_test_stack(stack_name)

        # create a cloud server with non exist image name
        t['Resources']['WebServer']['Properties']['image'] = 'Slackware'
        t['Resources']['WebServer']['Properties']['user_data'] = ''

        # Mock flavors
        self.m.StubOutWithMock(cloud_server.CloudServer, "flavors")
        cloud_server.CloudServer.flavors.__contains__('2').AndReturn(True)
        cloud_server.CloudServer.script = None
        self.m.ReplayAll()

        cs = cloud_server.CloudServer('cs_create_image_err',
                                      t['Resources']['WebServer'], stack)

        self.assertEqual(None, cs.validate())
        self.m.VerifyAll()
Example #5
0
    def test_cs_create_flavor_err(self):
        """validate() should throw an if the flavor is invalid."""
        stack_name = 'test_cs_create_flavor_err_stack'
        (t, stack) = self._setup_test_stack(stack_name)

        # create a cloud server with non exist image name
        t['Resources']['WebServer']['Properties']['flavor'] = '1'

        # Mock flavors
        self.m.StubOutWithMock(cloud_server.CloudServer, "flavors")
        flavors = ['2', '3', '4', '5', '6', '7', '8']
        cloud_server.CloudServer.flavors = flavors
        self.m.ReplayAll()

        cs = cloud_server.CloudServer('cs_create_flavor_err',
                                      t['Resources']['WebServer'], stack)

        self.assertEqual({'Error': "flavor not found."}, cs.validate())

        self.m.VerifyAll()