Ejemplo n.º 1
0
 def test_valid_durations(self):
     self.assertEqual(0, util.parse_isoduration('PT'))
     self.assertEqual(3600, util.parse_isoduration('PT1H'))
     self.assertEqual(120, util.parse_isoduration('PT2M'))
     self.assertEqual(3, util.parse_isoduration('PT3S'))
     self.assertEqual(3900, util.parse_isoduration('PT1H5M'))
     self.assertEqual(3605, util.parse_isoduration('PT1H5S'))
     self.assertEqual(303, util.parse_isoduration('PT5M3S'))
     self.assertEqual(3903, util.parse_isoduration('PT1H5M3S'))
     self.assertEqual(24 * 3600, util.parse_isoduration('PT24H'))
Ejemplo n.º 2
0
 def test_valid_durations(self):
     self.assertEqual(util.parse_isoduration('PT'), 0)
     self.assertEqual(util.parse_isoduration('PT1H'), 3600)
     self.assertEqual(util.parse_isoduration('PT2M'), 120)
     self.assertEqual(util.parse_isoduration('PT3S'), 3)
     self.assertEqual(util.parse_isoduration('PT1H5M'), 3900)
     self.assertEqual(util.parse_isoduration('PT1H5S'), 3605)
     self.assertEqual(util.parse_isoduration('PT5M3S'), 303)
     self.assertEqual(util.parse_isoduration('PT1H5M3S'), 3903)
     self.assertEqual(util.parse_isoduration('PT24H'), 24 * 3600)
 def _try_rolling_update(self, prop_diff):
     if (self.update_policy[self.ROLLING_UPDATE] and
             self.LAUNCH_CONFIGURATION_NAME in prop_diff):
         policy = self.update_policy[self.ROLLING_UPDATE]
         pause_sec = iso8601utils.parse_isoduration(policy[self.PAUSE_TIME])
         self._replace(policy[self.MIN_INSTANCES_IN_SERVICE],
                       policy[self.MAX_BATCH_SIZE],
                       pause_sec)
    def validate(self):
        """Add validation for update_policy."""
        super(InstanceGroup, self).validate()

        if self.update_policy is not None:
            policy_name = self.ROLLING_UPDATE
            if (policy_name in self.update_policy and
                    self.update_policy[policy_name] is not None):
                pause_time = self.update_policy[policy_name][self.PAUSE_TIME]
                if iso8601utils.parse_isoduration(pause_time) > 3600:
                    msg = _('Maximum %s is 1 hour.') % self.PAUSE_TIME
                    raise ValueError(msg)
Ejemplo n.º 5
0
    def _replace(self, min_in_service, batch_size, pause_time):
        """
        Replace the instances in the group using updated launch configuration
        """
        def changing_instances(tmpl):
            instances = self.get_instances()
            serialize_template = functools.partial(json.dumps, sort_keys=True)
            current = set((i.name, serialize_template(i.t)) for i in instances)
            updated = set((k, serialize_template(v))
                          for k, v in tmpl['Resources'].items())
            # includes instances to be updated and deleted
            affected = set(k for k, v in current ^ updated)
            return set(i.FnGetRefId() for i in instances if i.name in affected)

        def pause_between_batch():
            while True:
                try:
                    yield
                except scheduler.Timeout:
                    return

        capacity = len(self.nested()) if self.nested() else 0
        efft_bat_sz = min(batch_size, capacity)
        efft_min_sz = min(min_in_service, capacity)
        pause_sec = iso8601utils.parse_isoduration(pause_time)

        batch_cnt = (capacity + efft_bat_sz - 1) // efft_bat_sz
        if pause_sec * (batch_cnt - 1) >= self.stack.timeout_mins * 60:
            raise ValueError('The current UpdatePolicy will result '
                             'in stack update timeout.')

        # effective capacity includes temporary capacity added to accommodate
        # the minimum number of instances in service during update
        efft_capacity = max(capacity - efft_bat_sz, efft_min_sz) + efft_bat_sz

        try:
            remainder = capacity
            while remainder > 0 or efft_capacity > capacity:
                if capacity - remainder >= efft_min_sz:
                    efft_capacity = capacity
                template = self._create_template(efft_capacity, efft_bat_sz)
                self._lb_reload(exclude=changing_instances(template))
                updater = self.update_with_template(template,
                                                    self._environment())
                updater.run_to_completion()
                self.check_update_complete(updater)
                remainder -= efft_bat_sz
                if remainder > 0 and pause_sec > 0:
                    self._lb_reload()
                    waiter = scheduler.TaskRunner(pause_between_batch)
                    waiter(timeout=pause_sec)
        finally:
            self._lb_reload()
Ejemplo n.º 6
0
    def validate(self):
        """Add validation for update_policy."""
        super(InstanceGroup, self).validate()

        if self.update_policy is not None:
            policy_name = self.ROLLING_UPDATE
            if (policy_name in self.update_policy and
                    self.update_policy[policy_name] is not None):
                pause_time = self.update_policy[policy_name][self.PAUSE_TIME]
                if iso8601utils.parse_isoduration(pause_time) > 3600:
                    msg = _('Maximum %s is 1 hour.') % self.PAUSE_TIME
                    raise ValueError(msg)
Ejemplo n.º 7
0
    def _replace(self, min_in_service, batch_size, pause_time):
        """
        Replace the instances in the group using updated launch configuration
        """
        def changing_instances(tmpl):
            instances = self.get_instances()
            serialize_template = functools.partial(json.dumps, sort_keys=True)
            current = set((i.name, serialize_template(i.t)) for i in instances)
            updated = set((k, serialize_template(v))
                          for k, v in tmpl['Resources'].items())
            # includes instances to be updated and deleted
            affected = set(k for k, v in current ^ updated)
            return set(i.FnGetRefId() for i in instances if i.name in affected)

        def pause_between_batch():
            while True:
                try:
                    yield
                except scheduler.Timeout:
                    return

        capacity = len(self.nested()) if self.nested() else 0
        efft_bat_sz = min(batch_size, capacity)
        efft_min_sz = min(min_in_service, capacity)
        pause_sec = iso8601utils.parse_isoduration(pause_time)

        batch_cnt = (capacity + efft_bat_sz - 1) // efft_bat_sz
        if pause_sec * (batch_cnt - 1) >= self.stack.timeout_mins * 60:
            raise ValueError('The current UpdatePolicy will result '
                             'in stack update timeout.')

        # effective capacity includes temporary capacity added to accommodate
        # the minimum number of instances in service during update
        efft_capacity = max(capacity - efft_bat_sz, efft_min_sz) + efft_bat_sz

        try:
            remainder = capacity
            while remainder > 0 or efft_capacity > capacity:
                if capacity - remainder >= efft_min_sz:
                    efft_capacity = capacity
                template = self._create_template(efft_capacity, efft_bat_sz)
                self._lb_reload(exclude=changing_instances(template))
                updater = self.update_with_template(template,
                                                    self._environment())
                updater.run_to_completion()
                self.check_update_complete(updater)
                remainder -= efft_bat_sz
                if remainder > 0 and pause_sec > 0:
                    self._lb_reload()
                    waiter = scheduler.TaskRunner(pause_between_batch)
                    waiter(timeout=pause_sec)
        finally:
            self._lb_reload()
Ejemplo n.º 8
0
    def validate(self):
        """
        Add validation for update_policy
        """
        super(InstanceGroup, self).validate()

        if self.update_policy:
            self.update_policy.validate()
            policy_name = self.update_policy_schema.keys()[0]
            if self.update_policy[policy_name]:
                pause_time = self.update_policy[policy_name]['PauseTime']
                if iso8601utils.parse_isoduration(pause_time) > 3600:
                    raise ValueError('Maximum PauseTime is 1 hour.')
Ejemplo n.º 9
0
    def validate(self):
        """
        Add validation for update_policy
        """
        super(InstanceGroup, self).validate()

        if self.update_policy:
            self.update_policy.validate()
            policy_name = self.update_policy_schema.keys()[0]
            if self.update_policy[policy_name]:
                pause_time = self.update_policy[policy_name][self.PAUSE_TIME]
                if iso8601utils.parse_isoduration(pause_time) > 3600:
                    raise ValueError('Maximum PauseTime is 1 hour.')
Ejemplo n.º 10
0
    def validate(self):
        """
        Add validation for update_policy
        """
        super(InstanceGroup, self).validate()

        if self.update_policy:
            self.update_policy.validate()
            policy_name = self.update_policy_schema.keys()[0]
            if self.update_policy[policy_name]:
                pause_time = self.update_policy[policy_name][self.PAUSE_TIME]
                if iso8601utils.parse_isoduration(pause_time) > 3600:
                    msg = _('Maximum %s is 1 hour.') % self.PAUSE_TIME
                    raise ValueError(msg)