Exemple #1
0
 def got_request_bag(request_bag):
     log.msg("Executing launch config.")
     return launch_server_v1.launch_server(log,
                                           request_bag,
                                           scaling_group,
                                           launch_config['args'],
                                           undo)
Exemple #2
0
 def got_request_bag(request_bag):
     log.msg("Executing launch config.")
     return launch_server_v1.launch_server(log,
                                           request_bag,
                                           scaling_group,
                                           launch_config['args'],
                                           undo)
    def test_launch_server_propagates_wait_for_active_errors(
            self, wait_for_active, create_server, add_to_load_balancers):
        """
        launch_server will propagate any errors from wait_for_active.
        """
        launch_config = {'server': {'imageRef': '1', 'flavorRef': '1'},
                         'loadBalancers': []}

        server_details = {
            'server': {
                'id': '1',
                'addresses': {'private': [
                    {'version': 4, 'addr': '10.0.0.1'}]}}}

        create_server.return_value = succeed(server_details)

        wait_for_active.return_value = fail(
            APIError(500, "Oh noes")).addErrback(wrap_request_error, 'url')

        d = launch_server(self.log,
                          'DFW',
                          self.scaling_group,
                          fake_service_catalog,
                          'my-auth-token',
                          launch_config,
                          self.undo)

        failure = self.failureResultOf(d)
        failure.trap(RequestError)
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, "Oh noes")
Exemple #4
0
 def when_authenticated((auth_token, service_catalog)):
     log.msg("Executing launch config.")
     return launch_server_v1.launch_server(
         log,
         self.region,
         scaling_group,
         service_catalog,
         auth_token,
         launch_config['args'], undo)
    def test_launch_server_pushes_verified_delete_onto_undo(
            self, wait_for_active, create_server, add_to_load_balancers,
            verified_delete):
        """
        launch_server will push verified_delete onto the undo stack
        after the server is successfully created.
        """
        launch_config = {'server': {'imageRef': '1', 'flavorRef': '1'},
                         'loadBalancers': []}

        server_details = {
            'server': {
                'id': '1',
                'addresses': {'private': [
                    {'version': 4, 'addr': '10.0.0.1'}]}}}

        create_server.return_value = Deferred()

        wait_for_active.return_value = succeed(server_details)

        mock_server_response = {'server': {'id': '1',
                                           'addresses': {'private': [{'version': 4,
                                                                      'addr': '10.0.0.1'}]}}}
        mock_lb_response = [(12345, ('10.0.0.1', 80)), (54321, ('10.0.0.1', 81))]
        add_to_load_balancers.return_value = succeed((mock_server_response, mock_lb_response))

        d = launch_server(self.log,
                          'DFW',
                          self.scaling_group,
                          fake_service_catalog,
                          'my-auth-token',
                          launch_config,
                          self.undo)

        # Check that the push hasn't happened because create_server hasn't
        # succeeded yet.
        self.assertEqual(self.undo.push.call_count, 0)

        create_server.return_value.callback(server_details)

        self.successResultOf(d)

        self.undo.push.assert_called_once_with(
            verified_delete,
            mock.ANY,
            'http://dfw.openstack/',
            'my-auth-token',
            '1')
Exemple #6
0
    def test_launch_server_pushes_verified_delete_onto_undo(
            self, wait_for_active, create_server, add_to_load_balancers,
            verified_delete):
        """
        launch_server will push verified_delete onto the undo stack
        after the server is successfully created.
        """
        launch_config = {
            'server': {
                'imageRef': '1',
                'flavorRef': '1'
            },
            'loadBalancers': []
        }

        server_details = {
            'server': {
                'id': '1',
                'addresses': {
                    'private': [{
                        'version': 4,
                        'addr': '10.0.0.1'
                    }]
                }
            }
        }

        create_server.return_value = Deferred()

        wait_for_active.return_value = succeed(server_details)

        d = launch_server(self.log, 'DFW', self.scaling_group,
                          fake_service_catalog, 'my-auth-token', launch_config,
                          self.undo)

        # Check that the push hasn't happened because create_server hasn't
        # succeeded yet.
        self.assertEqual(self.undo.push.call_count, 0)

        create_server.return_value.callback(server_details)

        self.successResultOf(d)

        self.undo.push.assert_called_once_with(verified_delete, mock.ANY,
                                               'http://dfw.openstack/',
                                               'my-auth-token', '1')
    def test_launch_server_bobby(self, bobby_create_server, wait_for_active, create_server,
                                 add_to_load_balancers):
        """
        launch_server creates a server, waits until the server is active then
        adds the server's first private IPv4 address to any load balancers.
        """
        launch_config = {'server': {'imageRef': '1', 'flavorRef': '1'},
                         'loadBalancers': [
                             {'loadBalancerId': 12345, 'port': 80},
                             {'loadBalancerId': 54321, 'port': 81}
                         ]}

        server_detail = {
            'server': {
                'id': '1',
                'addresses': {'private': [
                    {'version': 4, 'addr': '10.0.0.1'}]}}}

        create_server.return_value = succeed(server_detail)

        wait_for_active.return_value = succeed(server_detail)

        add_to_load_balancers.return_value = succeed([
            (12345, ('10.0.0.1', 80)),
            (54321, ('10.0.0.1', 81))
        ])

        d = launch_server(self.log,
                          'DFW',
                          self.scaling_group,
                          fake_service_catalog,
                          'my-auth-token',
                          launch_config,
                          self.undo)

        result = self.successResultOf(d)
        self.assertEqual(
            result,
            (server_detail, [
                (12345, ('10.0.0.1', 80)),
                (54321, ('10.0.0.1', 81))]))

        bobby_create_server.assert_called_once_with('1234', self.scaling_group_uuid, '1')
Exemple #8
0
    def test_launch_server_propagates_add_to_load_balancers_errors(
            self, wait_for_active, create_server, add_to_load_balancers):
        """
        launch_server will propagate any errors from add_to_load_balancers.
        """
        launch_config = {
            'server': {
                'imageRef': '1',
                'flavorRef': '1'
            },
            'loadBalancers': []
        }

        server_details = {
            'server': {
                'id': '1',
                'addresses': {
                    'private': [{
                        'version': 4,
                        'addr': '10.0.0.1'
                    }]
                }
            }
        }

        create_server.return_value = succeed(server_details)

        wait_for_active.return_value = succeed(server_details)

        add_to_load_balancers.return_value = fail(APIError(
            500, "Oh noes")).addErrback(wrap_request_error, 'url')

        d = launch_server(self.log, 'DFW', self.scaling_group,
                          fake_service_catalog, 'my-auth-token', launch_config,
                          self.undo)

        failure = self.failureResultOf(d)
        failure.trap(RequestError)
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, "Oh noes")
Exemple #9
0
    def test_launch_server_propagates_create_server_errors(
            self, wait_for_active, create_server, add_to_load_balancers):
        """
        launch_server will propagate any errors from create_server.
        """
        create_server.return_value = fail(APIError(500, "Oh noes")).addErrback(
            wrap_request_error, 'url')

        d = launch_server(self.log, 'DFW', self.scaling_group,
                          fake_service_catalog, 'my-auth-token',
                          {'server': {}}, self.undo)

        failure = self.failureResultOf(d)
        failure.trap(RequestError)
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, "Oh noes")
    def test_launch_server_doesnt_push_undo_op_on_create_server_failure(
            self, create_server):
        """
        launch_server won't push anything onto the undo stack if create_server
        fails.
        """
        launch_config = {'server': {'imageRef': '1', 'flavorRef': '1'},
                         'loadBalancers': []}

        create_server.return_value = fail(APIError(500, ''))

        d = launch_server(self.log,
                          'DFW',
                          self.scaling_group,
                          fake_service_catalog,
                          'my-auth-token',
                          launch_config,
                          self.undo)

        self.failureResultOf(d, APIError)

        self.assertEqual(self.undo.push.call_count, 0)
Exemple #11
0
    def test_launch_server_propagates_create_server_errors(
            self, wait_for_active, create_server, add_to_load_balancers):
        """
        launch_server will propagate any errors from create_server.
        """
        create_server.return_value = fail(
            APIError(500, "Oh noes")).addErrback(wrap_request_error, 'url')

        d = launch_server(self.log,
                          'DFW',
                          self.scaling_group,
                          fake_service_catalog,
                          'my-auth-token',
                          {'server': {}})

        failure = self.failureResultOf(d)
        failure.trap(RequestError)
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, "Oh noes")
Exemple #12
0
    def test_launch_server_doesnt_push_undo_op_on_create_server_failure(
            self, create_server):
        """
        launch_server won't push anything onto the undo stack if create_server
        fails.
        """
        launch_config = {
            'server': {
                'imageRef': '1',
                'flavorRef': '1'
            },
            'loadBalancers': []
        }

        create_server.return_value = fail(APIError(500, ''))

        d = launch_server(self.log, 'DFW', self.scaling_group,
                          fake_service_catalog, 'my-auth-token', launch_config,
                          self.undo)

        self.failureResultOf(d, APIError)

        self.assertEqual(self.undo.push.call_count, 0)
Exemple #13
0
 def when_authenticated((auth_token, service_catalog)):
     log.msg("Executing launch config.")
     return launch_server_v1.launch_server(log, config_value('region'),
                                           scaling_group,
                                           service_catalog, auth_token,
                                           launch_config['args'], undo)
    def test_launch_server(self, wait_for_active, create_server,
                           add_to_load_balancers):
        """
        launch_server creates a server, waits until the server is active then
        adds the server's first private IPv4 address to any load balancers.
        """
        launch_config = {'server': {'imageRef': '1', 'flavorRef': '1'},
                         'loadBalancers': [
                             {'loadBalancerId': 12345, 'port': 80},
                             {'loadBalancerId': 54321, 'port': 81}
                         ]}

        load_balancer_metadata = {
            'rax:auto_scaling_server_name': 'as000000',
            'rax:auto_scaling_group_id': '1111111-11111-11111-11111111'}

        prepared_load_balancers = [
            {'loadBalancerId': 12345, 'port': 80,
             'metadata': load_balancer_metadata},
            {'loadBalancerId': 54321, 'port': 81,
             'metadata': load_balancer_metadata}
        ]

        expected_server_config = {
            'imageRef': '1', 'flavorRef': '1', 'name': 'as000000',
            'metadata': {
                'rax:auto_scaling_group_id': '1111111-11111-11111-11111111'}}

        server_details = {
            'server': {
                'id': '1',
                'addresses': {'private': [
                    {'version': 4, 'addr': '10.0.0.1'}]}}}

        create_server.return_value = succeed(server_details)

        wait_for_active.return_value = succeed(server_details)

        add_to_load_balancers.return_value = succeed([
            (12345, ('10.0.0.1', 80)),
            (54321, ('10.0.0.1', 81))
        ])

        d = launch_server(self.log,
                          'DFW',
                          self.scaling_group,
                          fake_service_catalog,
                          'my-auth-token',
                          launch_config,
                          self.undo)

        result = self.successResultOf(d)
        self.assertEqual(
            result,
            (server_details, [
                (12345, ('10.0.0.1', 80)),
                (54321, ('10.0.0.1', 81))]))

        create_server.assert_called_once_with('http://dfw.openstack/',
                                              'my-auth-token',
                                              expected_server_config)

        wait_for_active.assert_called_once_with(mock.ANY,
                                                'http://dfw.openstack/',
                                                'my-auth-token',
                                                '1')

        add_to_load_balancers.assert_called_once_with(
            'http://dfw.lbaas/', 'my-auth-token', prepared_load_balancers,
            '10.0.0.1', self.undo)
Exemple #15
0
    def test_launch_server(self, wait_for_active, create_server,
                           add_to_load_balancers):
        """
        launch_server creates a server, waits until the server is active then
        adds the server's first private IPv4 address to any load balancers.
        """
        launch_config = {
            'server': {
                'imageRef': '1',
                'flavorRef': '1'
            },
            'loadBalancers': [{
                'loadBalancerId': 12345,
                'port': 80
            }, {
                'loadBalancerId': 54321,
                'port': 81
            }]
        }

        load_balancer_metadata = {
            'rax:auto_scaling_server_name': 'as000000',
            'rax:auto_scaling_group_id': '1111111-11111-11111-11111111'
        }

        prepared_load_balancers = [{
            'loadBalancerId': 12345,
            'port': 80,
            'metadata': load_balancer_metadata
        }, {
            'loadBalancerId': 54321,
            'port': 81,
            'metadata': load_balancer_metadata
        }]

        expected_server_config = {
            'imageRef': '1',
            'flavorRef': '1',
            'name': 'as000000',
            'metadata': {
                'rax:auto_scaling_group_id': '1111111-11111-11111-11111111'
            }
        }

        server_details = {
            'server': {
                'id': '1',
                'addresses': {
                    'private': [{
                        'version': 4,
                        'addr': '10.0.0.1'
                    }]
                }
            }
        }

        create_server.return_value = succeed(server_details)

        wait_for_active.return_value = succeed(server_details)

        add_to_load_balancers.return_value = succeed([
            (12345, ('10.0.0.1', 80)), (54321, ('10.0.0.1', 81))
        ])

        d = launch_server(self.log, 'DFW', self.scaling_group,
                          fake_service_catalog, 'my-auth-token', launch_config,
                          self.undo)

        result = self.successResultOf(d)
        self.assertEqual(result, (server_details, [(12345, ('10.0.0.1', 80)),
                                                   (54321, ('10.0.0.1', 81))]))

        create_server.assert_called_once_with('http://dfw.openstack/',
                                              'my-auth-token',
                                              expected_server_config)

        wait_for_active.assert_called_once_with(mock.ANY,
                                                'http://dfw.openstack/',
                                                'my-auth-token', '1')

        add_to_load_balancers.assert_called_once_with('http://dfw.lbaas/',
                                                      'my-auth-token',
                                                      prepared_load_balancers,
                                                      '10.0.0.1', self.undo)