Exemple #1
0
 def setUp(self):
     self.tenant_id = 'tenant-id'
     self.group_id = 'group-id'
     self.state = GroupState(self.tenant_id, self.group_id, 'group-name',
                             {}, {}, None, {}, False,
                             ScalingGroupStatus.ACTIVE, desired=2)
     self.group = mock_group(self.state, self.tenant_id, self.group_id)
     self.lc = {'args': {'server': {'name': 'foo'}, 'loadBalancers': []}}
     self.desired_lbs = s(CLBDescription(lb_id='23', port=80))
     self.servers = (
         server('a', ServerState.ACTIVE, servicenet_address='10.0.0.1',
                desired_lbs=self.desired_lbs,
                links=freeze([{'href': 'link1', 'rel': 'self'}])),
         server('b', ServerState.ACTIVE, servicenet_address='10.0.0.2',
                desired_lbs=self.desired_lbs,
                links=freeze([{'href': 'link2', 'rel': 'self'}]))
     )
     self.state_active = {}
     self.cache = [thaw(self.servers[0].json), thaw(self.servers[1].json)]
     self.gsgi = GetScalingGroupInfo(tenant_id='tenant-id',
                                     group_id='group-id')
     self.manifest = {  # Many details elided!
         'state': self.state,
         'launchConfiguration': self.lc,
     }
     self.gsgi_result = (self.group, self.manifest)
     self.now = datetime(1970, 1, 1)
Exemple #2
0
 def test_multiple_lb_pending(self):
     """
     When a server needs to be added to multiple LBs, it's only counted
     once.
     """
     lb_nodes = [
         CLBNode(node_id='1',
                 description=CLBDescription(lb_id='foo', port=1),
                 address='1.1.1.1'),
         CLBNode(node_id='2',
                 description=CLBDescription(lb_id='foo', port=2),
                 address='1.1.1.1'),
         CLBNode(node_id='3',
                 description=CLBDescription(lb_id='bar', port=3),
                 address='1.1.1.1'),
         CLBNode(node_id='4',
                 description=CLBDescription(lb_id='bar', port=4),
                 address='1.1.1.1'),
     ]
     desired_lbs = s(CLBDescription(lb_id='foo', port=1),
                     CLBDescription(lb_id='foo', port=2),
                     CLBDescription(lb_id='bar', port=3),
                     CLBDescription(lb_id='bar', port=4))
     self.assertEqual(
         is_autoscale_active(
             server('id1', ServerState.ACTIVE, servicenet_address='1.1.1.1',
                    desired_lbs=desired_lbs),
             lb_nodes),
         True)
Exemple #3
0
    def test_success(self):
        """
        Executes the plan and returns SUCCESS when that's the most severe
        result.
        """
        dgs = get_desired_group_state(self.group_id, self.lc, 2)
        deleted = server(
            'c', ServerState.DELETED, servicenet_address='10.0.0.3',
            desired_lbs=self.desired_lbs,
            links=freeze([{'href': 'link3', 'rel': 'self'}]))
        self.servers += (deleted,)

        steps = [
            TestStep(
                Effect(
                    {'dgs': dgs,
                     'servers': self.servers,
                     'lb_nodes': (),
                     'now': 0})
                .on(lambda _: (StepResult.SUCCESS, [])))]

        def plan(dgs, servers, lb_nodes, now, build_timeout):
            self.assertEqual(build_timeout, 3600)
            return steps

        sequence = [
            parallel_sequence([]),
            (Log('execute-convergence',
                 dict(servers=self.servers, lb_nodes=(), steps=steps,
                      now=self.now, desired=dgs)), noop),
            parallel_sequence([
                [({'dgs': dgs, 'servers': self.servers,
                   'lb_nodes': (), 'now': 0},
                  noop)]
            ]),
            (Log('execute-convergence-results',
                 {'results': [{'step': steps[0],
                               'result': StepResult.SUCCESS,
                               'reasons': []}],
                  'worst_status': 'SUCCESS'}), noop),
            # Note that servers arg is non-deleted servers
            (UpdateServersCache(
                "tenant-id", "group-id", self.now,
                [thaw(self.servers[0].json.set("_is_as_active", True)),
                 thaw(self.servers[1].json.set("_is_as_active", True))]),
             noop)
        ]

        # all the servers updated in cache in beginning
        self.cache.append(thaw(deleted.json))

        self.assertEqual(
            perform_sequence(self.get_seq() + sequence, self._invoke(plan)),
            (StepResult.SUCCESS, ScalingGroupStatus.ACTIVE))
Exemple #4
0
 def test_lb_pending(self):
     """
     When a server should be in a LB but it's not, it's not active.
     """
     desired_lbs = s(CLBDescription(lb_id='foo', port=80))
     lb_nodes = [
         CLBNode(node_id='x',
                 description=CLBDescription(lb_id='foo', port=80),
                 address='1.1.1.3')]
     self.assertEqual(
         is_autoscale_active(
             server('id1', ServerState.ACTIVE, servicenet_address='1.1.1.1',
                    desired_lbs=desired_lbs),
             lb_nodes),
         False)
Exemple #5
0
 def test_non_active(self):
     """ Non-active server is not considered AS active """
     self.assertEqual(
         is_autoscale_active(server('id1', ServerState.BUILD), []),
         False)
Exemple #6
0
 def test_active(self):
     """Built server with no desired LBs is active."""
     self.assertEqual(
         is_autoscale_active(server('id1', ServerState.ACTIVE), []),
         True)