Ejemplo n.º 1
0
    def _xml_ele_to_obj(cls, element):
        pool_dict = element.attrib
        # XML data types differ from JSON, so we normalize here
        # Cast boolean
        if 'admin_state_up' in pool_dict:
            pool_dict['admin_state_up'] = cls._string_to_bool(
                pool_dict.get('admin_state_up'))

        # Process single entity models
        session_persistence = None
        if element.find(SessionPersistence.ROOT_TAG) is not None:
            session_persistence = SessionPersistence._xml_ele_to_obj(
                element.find(SessionPersistence.ROOT_TAG))

        pool = Pool(id_=pool_dict.get('id'),
                    name=pool_dict.get('name'),
                    description=pool_dict.get('description'),
                    tenant_id=pool_dict.get('tenant_id'),
                    protocol=pool_dict.get('protocol'),
                    lb_algorithm=pool_dict.get('lb_algorithm'),
                    healthmonitor_id=pool_dict.get('healthmonitor_id'),
                    admin_state_up=pool_dict.get('admin_state_up'),
                    status=pool_dict.get('status'),
                    session_persistence=session_persistence)
        return pool
Ejemplo n.º 2
0
    def _xml_ele_to_obj(cls, element):
        pool_dict = element.attrib
        # XML data types differ from JSON, so we normalize here
        # Cast boolean
        if 'admin_state_up' in pool_dict:
            pool_dict['admin_state_up'] = cls._string_to_bool(
                pool_dict.get('admin_state_up'))

        # Process single entity models
        session_persistence = None
        if element.find(SessionPersistence.ROOT_TAG) is not None:
            session_persistence = SessionPersistence._xml_ele_to_obj(
                element.find(SessionPersistence.ROOT_TAG))

        pool = Pool(
            id_=pool_dict.get('id'),
            name=pool_dict.get('name'),
            description=pool_dict.get('description'),
            tenant_id=pool_dict.get('tenant_id'),
            protocol=pool_dict.get('protocol'),
            lb_algorithm=pool_dict.get('lb_algorithm'),
            healthmonitor_id=pool_dict.get('healthmonitor_id'),
            admin_state_up=pool_dict.get('admin_state_up'),
            status=pool_dict.get('status'),
            session_persistence=session_persistence)
        return pool
Ejemplo n.º 3
0
    def test_session_persistence_xml(self):

        actual_xml = """{xml_header}
                            <{root_tag}
                                type="{type_}"
                                cookie_name="{cookie_name}"
                            xmlns="{xmlns}" />""".format(
            xml_header=self.XML_HEADER,
            xmlns=self.XML_NS,
            root_tag=self.ROOT_TAG,
            type_=self.type_,
            cookie_name=self.cookie_name)
        actual_obj = SessionPersistence.deserialize(actual_xml, 'xml')
        self.assertEqual(self.expected_obj, actual_obj)
Ejemplo n.º 4
0
    def test_session_persistence_json(self):

        actual_json = """
                        {{ "{root_tag}":
                            {{
                                "type": "{type_}",
                                "cookie_name": "{cookie_name}"
                            }}
                        }}
                        """.format(root_tag=self.ROOT_TAG,
                                   type_=self.type_,
                                   cookie_name=self.cookie_name)
        actual_obj = SessionPersistence.deserialize(actual_json, 'json')
        self.assertEqual(self.expected_obj, actual_obj)
Ejemplo n.º 5
0
    def _dict_to_obj(cls, pool_dict):

        # Process single entity models
        session_persistence = None
        if SessionPersistence.ROOT_TAG in pool_dict:
            session_persistence = SessionPersistence._dict_to_obj(
                pool_dict[SessionPersistence.ROOT_TAG])

        pool = Pool(id_=pool_dict.get('id'),
                    name=pool_dict.get('name'),
                    description=pool_dict.get('description'),
                    tenant_id=pool_dict.get('tenant_id'),
                    protocol=pool_dict.get('protocol'),
                    lb_algorithm=pool_dict.get('lb_algorithm'),
                    healthmonitor_id=pool_dict.get('healthmonitor_id'),
                    admin_state_up=pool_dict.get('admin_state_up'),
                    status=pool_dict.get('status'),
                    session_persistence=session_persistence)
        return pool
Ejemplo n.º 6
0
    def _dict_to_obj(cls, pool_dict):

        # Process single entity models
        session_persistence = None
        if SessionPersistence.ROOT_TAG in pool_dict:
            session_persistence = SessionPersistence._dict_to_obj(
                pool_dict[SessionPersistence.ROOT_TAG])

        pool = Pool(
            id_=pool_dict.get('id'),
            name=pool_dict.get('name'),
            description=pool_dict.get('description'),
            tenant_id=pool_dict.get('tenant_id'),
            protocol=pool_dict.get('protocol'),
            lb_algorithm=pool_dict.get('lb_algorithm'),
            healthmonitor_id=pool_dict.get('healthmonitor_id'),
            admin_state_up=pool_dict.get('admin_state_up'),
            status=pool_dict.get('status'),
            session_persistence=session_persistence)
        return pool
Ejemplo n.º 7
0
    def setUpClass(cls):
        super(BasePoolResponseTest, cls).setUpClass()
        cls.XML_HEADER = Constants.XML_HEADER
        cls.XML_NS = Constants.XML_API_NAMESPACE
        cls.id_ = "8992a43f-83af-4b49-9afd-c2bfbd82d7d7"
        cls.name = "Example HTTPS Pool"
        cls.description = "A simple example of an HTTPS pool."
        cls.tenant_id = "7725fe12-1c14-4f45-ba8e-44bf01763578"
        cls.protocol = "HTTPS"
        cls.lb_algorithm = "ROUND_ROBIN"
        cls.healthmonitor_id = "8311446e-8a13-4c00-95b3-03a92f9759c7"
        cls.admin_state_up = True
        cls.status = "ACTIVE"
        cls.persistence_type = "COOKIE"
        cls.cookie_name = "session_persistence_cookie"
        cls.session_persistence_obj = SessionPersistence(
            type_=cls.persistence_type,
            cookie_name=cls.cookie_name)

        cls.pool_obj = Pool(
            id_=cls.id_, name=cls.name, description=cls.description,
            tenant_id=cls.tenant_id, protocol=cls.protocol,
            lb_algorithm=cls.lb_algorithm,
            healthmonitor_id=cls.healthmonitor_id,
            admin_state_up=cls.admin_state_up,
            status=cls.status,
            session_persistence=cls.session_persistence_obj)
        pool_list = [cls.pool_obj]
        cls.pools_obj = Pools(pool_list)

        cls.pool_attribute_kwargs = {
            "id_": cls.id_,
            "name": cls.name,
            "description": cls.description,
            "tenant_id": cls.tenant_id,
            "protocol": cls.protocol,
            "lb_algorithm": cls.lb_algorithm,
            "healthmonitor_id": cls.healthmonitor_id,
            "admin_state_up": str(cls.admin_state_up).lower(),
            "status": cls.status,
            "persistence_type": cls.persistence_type,
            "cookie_name": cls.cookie_name,
        }
        cls.actual_json_base = """
                    "id": "{id_}",
                    "name":"{name}",
                    "description":"{description}",
                    "tenant_id": "{tenant_id}",
                    "protocol": "{protocol}",
                    "lb_algorithm": "{lb_algorithm}",
                    "healthmonitor_id": "{healthmonitor_id}",
                    "admin_state_up": {admin_state_up},
                    "status": "{status}",
                    "session_persistence": {{
                        "type": "{persistence_type}",
                        "cookie_name": "{cookie_name}"
                    }}
        """.format(**cls.pool_attribute_kwargs)

        cls.actual_xml_base = """
                    id="{id_}"
                    name="{name}"
                    description="{description}"
                    tenant_id="{tenant_id}"
                    protocol="{protocol}"
                    lb_algorithm="{lb_algorithm}"
                    healthmonitor_id="{healthmonitor_id}"
                    admin_state_up="{admin_state_up}"
                    status="{status}" >
                    <session_persistence
                        type="{persistence_type}"
                        cookie_name="{cookie_name}"
                    />
        """.format(**cls.pool_attribute_kwargs)