Esempio n. 1
0
    def test_equal_circular_objs(self):
        class Cls(object):
            pass

        lst1 = [1, 2, 3]
        lst2 = [1, 2, 3]
        lst1.append(lst1)
        lst2.append(lst2)

        dct1 = {'one': 10, 'two': lst1}
        dct2 = {'one': 10, 'two': lst1}

        obj1 = Cls()
        obj2 = Cls()
        obj1.a = obj2.a = 10
        obj1.self = obj1
        obj2.self = obj2

        comparison = utils.is_different(lst1, lst2)
        comparison2 = utils.is_different(dct1, dct2)
        comparison3 = utils.is_different(obj1, obj2)

        self.assertFalse(comparison)
        self.assertFalse(comparison2)
        self.assertFalse(comparison3)
Esempio n. 2
0
    def test_equal_circular_objs(self):
        class Cls(object):
            pass

        lst1 = [1, 2, 3]
        lst2 = [1, 2, 3]
        lst1.append(lst1)
        lst2.append(lst2)

        dct1 = {'one': 10, 'two': lst1}
        dct2 = {'one': 10, 'two': lst1}

        obj1 = Cls()
        obj2 = Cls()
        obj1.a = obj2.a = 10
        obj1.self = obj1
        obj2.self = obj2

        comparison = utils.is_different(lst1, lst2)
        comparison2 = utils.is_different(dct1, dct2)
        comparison3 = utils.is_different(obj1, obj2)

        self.assertFalse(comparison)
        self.assertFalse(comparison2)
        self.assertFalse(comparison3)
Esempio n. 3
0
    def test_strings_are_compared_regardless_of_type(self):
        str1 = 'string'
        str2 = u'string'

        comparison = utils.is_different(str1, str2)

        self.assertFalse(comparison)
Esempio n. 4
0
    def push(self):
        if self._applied or self._template is None:
            return

        if 'heat_template_version' not in self._template:
            self._template['heat_template_version'] = HEAT_TEMPLATE_VERSION

        if 'description' not in self._template and self._description:
            self._template['description'] = self._description

        template = copy.deepcopy(self._template)
        LOG.info('Pushing: {0}'.format(template))

        current_status = self._get_status()
        resources = template.get('Resources') or template.get('resources')
        if current_status == 'NOT_FOUND':
            if resources:
                self._heat_client.stacks.create(stack_name=self._name,
                                                parameters=self._parameters,
                                                template=template,
                                                disable_rollback=True)

                self._wait_state(lambda status: status == 'CREATE_COMPLETE')
        else:
            if resources:
                self._heat_client.stacks.update(stack_id=self._name,
                                                parameters=self._parameters,
                                                template=template)
                self._wait_state(lambda status: status == 'UPDATE_COMPLETE')
            else:
                self.delete()

        self._applied = not utils.is_different(self._template, template)
Esempio n. 5
0
    def test_different_objs(self):
        class Cls1(object):
            a = 10

        class Cls2(object):
            b = 20

        obj1 = Cls1()
        obj2 = Cls2()
        obj3 = Cls1()
        obj3.a = {'one': 14, 'two': [(1, 2, 3), 'more']}

        comparison1 = utils.is_different(obj1, obj2)
        comparison2 = utils.is_different(obj1, obj3)

        self.assertTrue(comparison1)
        self.assertTrue(comparison2)
Esempio n. 6
0
    def test_different_objs(self):
        class Cls1(object):
            a = 10

        class Cls2(object):
            b = 20

        obj1 = Cls1()
        obj2 = Cls2()
        obj3 = Cls1()
        obj3.a = {'one': 14, 'two': [(1, 2, 3), 'more']}

        comparison1 = utils.is_different(obj1, obj2)
        comparison2 = utils.is_different(obj1, obj3)

        self.assertTrue(comparison1)
        self.assertTrue(comparison2)
Esempio n. 7
0
    def test_different_circular_objs(self):
        class Cls(object):
            pass

        obj1 = Cls()
        obj2 = Cls()
        obj1.self = obj1
        obj2.self = {'self': obj2}

        dct1 = {'one': [1, 2], 'three': 10}
        dct2 = {'one': [1, 2]}
        dct1['self'] = dct1
        dct2['self'] = dct2

        comparison = utils.is_different(obj1, obj2)
        comparison1 = utils.is_different(dct1, dct2)

        self.assertTrue(comparison)
        self.assertTrue(comparison1)
Esempio n. 8
0
    def test_different_circular_objs(self):
        class Cls(object):
            pass

        obj1 = Cls()
        obj2 = Cls()
        obj1.self = obj1
        obj2.self = {'self': obj2}

        dct1 = {'one': [1, 2], 'three': 10}
        dct2 = {'one': [1, 2]}
        dct1['self'] = dct1
        dct2['self'] = dct2

        comparison = utils.is_different(obj1, obj2)
        comparison1 = utils.is_different(dct1, dct2)

        self.assertTrue(comparison)
        self.assertTrue(comparison1)
Esempio n. 9
0
def merge_lists(list1, list2):
    result = []
    for item in list1 + list2:
        exists = False
        for old_item in result:
            if not utils.is_different(item, old_item):
                exists = True
                break
        if not exists:
            result.append(item)
    return result
Esempio n. 10
0
    def push(self):
        if self._applied or self._template is None:
            return

        self._tags = ','.join(CONF.heat.stack_tags)
        if 'heat_template_version' not in self._template:
            self._template['heat_template_version'] = HEAT_TEMPLATE_VERSION

        if 'description' not in self._template and self._description:
            self._template['description'] = self._description

        template = copy.deepcopy(self._template)
        LOG.debug('Pushing: {template}'.format(template=template))

        while True:
            try:
                current_status = self._get_status()
                resources = template.get('Resources') or template.get(
                    'resources')
                if current_status == 'NOT_FOUND':
                    if resources is not None:
                        token_client = self._get_token_client()
                        token_client.stacks.create(
                            stack_name=self._name,
                            parameters=self._parameters,
                            template=template,
                            files=self._files,
                            environment=self._hot_environment,
                            disable_rollback=True,
                            tags=self._tags)

                        self._wait_state(
                            lambda status: status == 'CREATE_COMPLETE')
                else:
                    if resources is not None:
                        self._client.stacks.update(
                            stack_id=self._name,
                            parameters=self._parameters,
                            files=self._files,
                            environment=self._hot_environment,
                            template=template,
                            disable_rollback=True,
                            tags=self._tags)
                        self._wait_state(
                            lambda status: status == 'UPDATE_COMPLETE', True)
                    else:
                        self.delete()
            except heat_exc.HTTPConflict as e:
                LOG.warning(_LW('Conflicting operation: {msg}').format(msg=e))
                eventlet.sleep(3)
            else:
                break

        self._applied = not utils.is_different(self._template, template)
Esempio n. 11
0
    def push(self):
        if self._applied or self._template is None:
            return

        self._tags = ','.join(CONF.heat.stack_tags)
        if 'heat_template_version' not in self._template:
            self._template['heat_template_version'] = HEAT_TEMPLATE_VERSION

        if 'description' not in self._template and self._description:
            self._template['description'] = self._description

        template = copy.deepcopy(self._template)
        LOG.debug('Pushing: {template}'.format(template=template))

        while True:
            try:
                current_status = self._get_status()
                resources = template.get('Resources') or template.get(
                    'resources')
                if current_status == 'NOT_FOUND':
                    if resources is not None:
                        token_client = self._get_token_client()
                        token_client.stacks.create(
                            stack_name=self._name,
                            parameters=self._parameters,
                            template=template,
                            files=self._files,
                            environment=self._hot_environment,
                            disable_rollback=True,
                            tags=self._tags)

                        self._wait_state(
                            lambda status: status == 'CREATE_COMPLETE')
                else:
                    if resources is not None:
                        self._client.stacks.update(
                            stack_id=self._name,
                            parameters=self._parameters,
                            files=self._files,
                            environment=self._hot_environment,
                            template=template,
                            disable_rollback=True,
                            tags=self._tags)
                        self._wait_state(
                            lambda status: status == 'UPDATE_COMPLETE', True)
                    else:
                        self.delete()
            except heat_exc.HTTPConflict as e:
                LOG.warning(_LW('Conflicting operation: {msg}').format(msg=e))
                eventlet.sleep(3)
            else:
                break

        self._applied = not utils.is_different(self._template, template)
Esempio n. 12
0
def merge_lists(list1, list2):
    result = []
    for item in list1 + list2:
        exists = False
        for old_item in result:
            if not utils.is_different(item, old_item):
                exists = True
                break
        if not exists:
            result.append(item)
    return result
Esempio n. 13
0
    def test_equal_objs(self):
        class Cls(object):
            pass

        obj1 = Cls()
        obj2 = Cls()
        obj1.a = {'one': 14, 'two': [(1, 2, 3), 'more']}
        obj2.a = {'one': 14, 'two': [(1, 2, 3), 'more']}

        comparison = utils.is_different(obj1, obj2)

        self.assertFalse(comparison)
Esempio n. 14
0
    def test_equal_objs(self):
        class Cls(object):
            pass

        obj1 = Cls()
        obj2 = Cls()
        obj1.a = {'one': 14, 'two': [(1, 2, 3), 'more']}
        obj2.a = {'one': 14, 'two': [(1, 2, 3), 'more']}

        comparison = utils.is_different(obj1, obj2)

        self.assertFalse(comparison)
Esempio n. 15
0
    def push(self):
        if self._applied or self._template is None:
            return

        self._tags = ",".join(CONF.heat.stack_tags)
        if "heat_template_version" not in self._template:
            self._template["heat_template_version"] = HEAT_TEMPLATE_VERSION

        if "description" not in self._template and self._description:
            self._template["description"] = self._description

        template = copy.deepcopy(self._template)
        LOG.debug("Pushing: {template}".format(template=template))

        current_status = self._get_status()
        resources = template.get("Resources") or template.get("resources")
        if current_status == "NOT_FOUND":
            if resources is not None:
                token_client = self._clients.get_heat_client(use_trusts=False)
                token_client.stacks.create(
                    stack_name=self._name,
                    parameters=self._parameters,
                    template=template,
                    files=self._files,
                    environment=self._hot_environment,
                    disable_rollback=True,
                    tags=self._tags,
                )

                self._wait_state(lambda status: status == "CREATE_COMPLETE")
        else:
            if resources is not None:
                trust_client = self._clients.get_heat_client()

                trust_client.stacks.update(
                    stack_id=self._name,
                    parameters=self._parameters,
                    files=self._files,
                    environment=self._hot_environment,
                    template=template,
                    disable_rollback=True,
                    tags=self._tags,
                )
                self._wait_state(lambda status: status == "UPDATE_COMPLETE", True)
            else:
                self.delete()

        self._applied = not utils.is_different(self._template, template)
Esempio n. 16
0
    def push(self):
        if self._applied or self._template is None:
            return

        if 'heat_template_version' not in self._template:
            self._template['heat_template_version'] = HEAT_TEMPLATE_VERSION

        if 'description' not in self._template and self._description:
            self._template['description'] = self._description

        template = copy.deepcopy(self._template)
        LOG.debug('Pushing: {template}'.format(template=template))

        current_status = self._get_status()
        resources = template.get('Resources') or template.get('resources')
        if current_status == 'NOT_FOUND':
            if resources is not None:
                token_client = self._clients.get_heat_client(use_trusts=False)
                token_client.stacks.create(
                    stack_name=self._name,
                    parameters=self._parameters,
                    template=template,
                    files=self._files,
                    environment=self._hot_environment,
                    disable_rollback=True)

                self._wait_state(lambda status: status == 'CREATE_COMPLETE')
        else:
            if resources is not None:
                trust_client = self._clients.get_heat_client()

                trust_client.stacks.update(
                    stack_id=self._name,
                    parameters=self._parameters,
                    files=self._files,
                    environment=self._hot_environment,
                    template=template,
                    disable_rollback=True)
                self._wait_state(
                    lambda status: status == 'UPDATE_COMPLETE', True)
            else:
                self.delete()

        self._applied = not utils.is_different(self._template, template)
Esempio n. 17
0
    def push(self, _context):
        if self._applied or self._template is None:
            return

        if "heat_template_version" not in self._template:
            self._template["heat_template_version"] = HEAT_TEMPLATE_VERSION

        if "description" not in self._template and self._description:
            self._template["description"] = self._description

        template = copy.deepcopy(self._template)
        LOG.info(_LI("Pushing: {0}").format(template))

        current_status = self._get_status(_context)
        resources = template.get("Resources") or template.get("resources")
        if current_status == "NOT_FOUND":
            if resources is not None:
                token_client = self._clients.get_heat_client(_context, False)
                token_client.stacks.create(
                    stack_name=self._name,
                    parameters=self._parameters,
                    template=template,
                    files=self._files,
                    disable_rollback=True,
                )

                self._wait_state(_context, lambda status: status == "CREATE_COMPLETE")
        else:
            if resources is not None:
                trust_client = self._clients.get_heat_client(_context)

                trust_client.stacks.update(
                    stack_id=self._name,
                    parameters=self._parameters,
                    files=self._files,
                    template=template,
                    disable_rollback=True,
                )
                self._wait_state(_context, lambda status: status == "UPDATE_COMPLETE", True)
            else:
                self.delete(_context)

        self._applied = not utils.is_different(self._template, template)
Esempio n. 18
0
    def push(self, _context):
        if self._applied or self._template is None:
            return

        if 'heat_template_version' not in self._template:
            self._template['heat_template_version'] = HEAT_TEMPLATE_VERSION

        if 'description' not in self._template and self._description:
            self._template['description'] = self._description

        template = copy.deepcopy(self._template)
        LOG.info(_LI('Pushing: {0}').format(template))

        current_status = self._get_status(_context)
        resources = template.get('Resources') or template.get('resources')
        if current_status == 'NOT_FOUND':
            if resources is not None:
                token_client = self._clients.get_heat_client(_context, False)
                token_client.stacks.create(
                    stack_name=self._name,
                    parameters=self._parameters,
                    template=template,
                    disable_rollback=True)

                self._wait_state(
                    _context,
                    lambda status: status == 'CREATE_COMPLETE')
        else:
            if resources is not None:
                trust_client = self._clients.get_heat_client(_context)

                trust_client.stacks.update(
                    stack_id=self._name,
                    parameters=self._parameters,
                    template=template,
                    disable_rollback=True)
                self._wait_state(
                    _context,
                    lambda status: status == 'UPDATE_COMPLETE')
            else:
                self.delete(_context)

        self._applied = not utils.is_different(self._template, template)
Esempio n. 19
0
 def test_equal_dicts(self):
     obj1 = {'first': 10, 'second': 12}
     obj2 = {'second': 12, 'first': 10}
     comparison = utils.is_different(obj1, obj2)
     self.assertFalse(comparison)
Esempio n. 20
0
 def test_different_dicts(self):
     obj1 = {'first': 10, 'second': 11}
     obj2 = {'first': 10, 'second': 12}
     comparison = utils.is_different(obj1, obj2)
     self.assertTrue(comparison)
Esempio n. 21
0
    def push(self):
        while pushing.get(self._name, False):
            eventlet.sleep(5)

        _template = cache.get(self._name)
        if applied.get(self._name, True) or _template is None:
            return

        self._tags = ','.join(CONF.heat.stack_tags)
        if 'heat_template_version' not in _template:
            _template['heat_template_version'] = HEAT_TEMPLATE_VERSION

        if 'description' not in _template and self._description:
            _template['description'] = self._description

        pushing[self._name] = True
        template = copy.deepcopy(_template)
        LOG.info('Pushing {0}: {1}'.format(self._name, template))

        while True:
            try:
                current_status = self._get_status()
                resources = template.get('Resources') or template.get(
                    'resources')
                if current_status == 'NOT_FOUND':
                    if resources is not None:
                        token_client = self._get_token_client()
                        token_client.stacks.create(
                            stack_name=self._name,
                            parameters=self._parameters,
                            template=template,
                            files=self._files,
                            environment=self._hot_environment,
                            disable_rollback=True,
                            tags=self._tags)

                        self._output = self._wait_state(
                            lambda status: status == 'CREATE_COMPLETE')
                else:
                    if resources is not None:
                        self._client.stacks.update(
                            stack_id=self._name,
                            parameters=self._parameters,
                            files=self._files,
                            environment=self._hot_environment,
                            template=template,
                            disable_rollback=True,
                            tags=self._tags)
                        self._output = self._wait_state(
                            lambda status: status == 'UPDATE_COMPLETE', True)
                    else:
                        self.delete()
            except heat_exc.HTTPConflict as e:
                LOG.warning(_LW('Conflicting operation: {msg}').format(msg=e))
                eventlet.sleep(3)
            except EnvironmentError as ee:
                LOG.warning(_LW('Heat Stack Error: {msg}').format(msg=ee))
                pushing[self._name] = False
                raise ee
            else:
                break

        pushing[self._name] = False
        applied[self._name] = not utils.is_different(cache.get(self._name).get('resources', {}), template.get('resources', {}))
        LOG.info('Pushing {0}: end with applied={1}'.format(self._name, applied.get(self._name, True)))
Esempio n. 22
0
 def test_equal_dicts(self):
     obj1 = {'first': 10, 'second': 12}
     obj2 = {'second': 12, 'first': 10}
     comparison = utils.is_different(obj1, obj2)
     self.assertFalse(comparison)
Esempio n. 23
0
 def test_different_dicts(self):
     obj1 = {'first': 10, 'second': 11}
     obj2 = {'first': 10, 'second': 12}
     comparison = utils.is_different(obj1, obj2)
     self.assertTrue(comparison)