예제 #1
0
    def test_json_body_2(self):
        self.maxDiff = None
        url = "/api/config/multi-key"
        body = _collapse_string('''
{
  "multi-key" :
  [
    {
      "foo" : "key part 1",
      "bar" : "key part 2",
      "treasure" : "some string"
    },
    {
      "foo" : "other key part 1",
      "bar" : "other key part 2",
      "treasure" : "some other string"
    }
  ]
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><multi-key xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">key part 1</foo><bar xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">key part 2</bar><treasure xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some string</treasure></multi-key><multi-key xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">other key part 1</foo><bar xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">other key part 2</bar><treasure xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some other string</treasure></multi-key></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body,"json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #2
0
    def test_xml_body_3(self):
        self.maxDiff = None
        url = "/api/config/top-list-deep"
        body = _collapse_string('''
<top-list-deep>
  <k>some key<k>
  <inner-list>
    <k>some other key</k?
    <a>some string</a>
    <inner-container>
      <a>some other string</a>
    </inner-container>      
  </inner-list>
  <inner-container-shallow>
    <a>yet a third string</a>
  </inner-container-shallow>    
  <inner-container-deep>
    <bottom-list-shallow>
      <k>yet a third key</a>
    </bottom-list-shallow>
  </inner-container-deep>    
</top-list-deep>
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-list-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><k>some key<k><inner-list><k>some other key</k?<a>some string</a><inner-container><a>some other string</a></inner-container></inner-list><inner-container-shallow><a>yet a third string</a></inner-container-shallow><inner-container-deep><bottom-list-shallow><k>yet a third key</a></bottom-list-shallow></inner-container-deep></top-list-deep></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "xml"))

        self.assertEqual(actual_xml, expected_xml)
예제 #3
0
    def test_conversion_XML_to_JSON_version(self):
        self.maxDiff = None
        url = "/api/config/car/toyota/models"
        xml = _collapse_string('''
<data>
          <car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
            <models>
              <name-m>Camry</name-m>	  
              <year>2015</year>	  
              <capacity>5</capacity>	  
              <version_str>2.0</version_str>
            </models>
          </car>
        </data>
        ''')
        #

        expected_json = _collapse_string('''
{"vehicle-a:models":[{"year" : 2015,"name-m" : "Camry","capacity" : 5, "version_str":"2.0"}]}
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        converter = XmlToJsonTranslator(schema, logger)

        xpath = create_xpath_from_url(url, schema)

        actual_json = converter.convert(False, url, xpath, xml)

        actual = _ordered(json.loads(actual_json))
        expected = _ordered(json.loads(expected_json))

        self.assertEquals(actual, expected)
예제 #4
0
    def test_json_body_1(self):
        self.maxDiff = None
        url = "/api/config/top-list-shallow/"
        body = _collapse_string('''
{
  "top-list-shallow"  :
  [
    {
      "k" : "some key 1"
    },
    {
      "k" : "some key 2"
    }

  ]
}

        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-list-shallow xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some key 1</k></top-list-shallow><top-list-shallow xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some key 2</k></top-list-shallow></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #5
0
    def test_conversion_XML_to_JSON_null_string(self):
        self.maxDiff = None
        url = "/api/operational/car/toyota/models"
        xml = _collapse_string(
            """
        <data>
          <car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
            <models>
              <name-m/>
            </models>
          </car>
        </data>
        """
        )

        expected_json = _collapse_string(
            """
        {"vehicle-a:models":[{"name-m" : ""}]}
        """
        )

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        converter = XmlToJsonTranslator(schema, logger)

        xpath = create_xpath_from_url(url, schema)

        actual_json = converter.convert(False, url, xpath, xml)

        actual = _ordered(json.loads(actual_json))
        expected = _ordered(json.loads(expected_json))

        self.assertEquals(actual, expected)
예제 #6
0
    def test_json_body_8(self):
        self.maxDiff = None
        url = "/api/config/top-container-deep/inner-container"
        body = _collapse_string('''
{
    "a":"another string",
    "inner-list":[
        {
            "k":"another key thing"
        }
    ]
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-container-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><vehicle-a:inner-container xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace">another string</a><inner-list xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">another key thing</k></inner-list></vehicle-a:inner-container></top-container-deep></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #7
0
    def test_json_body_7(self):
        self.maxDiff = None
        url = "/api/config/top-list-deep/key1/inner-list/key2"
        body = _collapse_string(
            """
{
    "inner-list":[
        {
            "k":"key2"
        }
    ]
}
        """
        )

        expected_xml = _collapse_string(
            """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-list-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k>key1</k><inner-list xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">key2</k></inner-list></top-list-deep></config>
        """
        )

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #8
0
    def test_PUT_deep_list_container(self):
        self.maxDiff = None
        url = "/v2/api/running/top-list-deep/key_top/inner-list/key_inner/inner-container"
        body = _collapse_string(
            """
{
      "inner-container" : {
        "a" : "a_value"
      }
}
        """
        )
        schema = load_multiple_schema_root(["vehicle-a"])
        converter = ConfdRestTranslatorV2(schema)
        actual_xml = converter.convert("PUT", url, (body, "json"))
        expected_xml = _collapse_string(
            """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
  <top-list-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
    <k>key_top</k>
    <inner-list xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
      <k>key_inner</k>
      <vehicle-a:inner-container xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace">
        <a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">a_value</a>
      </vehicle-a:inner-container>
    </inner-list>
  </top-list-deep>
</config>        
        """
        )
        self.assertEqual(actual_xml, expected_xml)
예제 #9
0
    def test_json_body_2(self):
        self.maxDiff = None
        url = "/api/config/multi-key"
        body = _collapse_string('''
{
  "multi-key" :
  [
    {
      "foo" : "key part 1",
      "bar" : "key part 2",
      "treasure" : "some string"
    },
    {
      "foo" : "other key part 1",
      "bar" : "other key part 2",
      "treasure" : "some other string"
    }
  ]
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><multi-key xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">key part 1</foo><bar xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">key part 2</bar><treasure xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some string</treasure></multi-key><multi-key xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">other key part 1</foo><bar xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">other key part 2</bar><treasure xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some other string</treasure></multi-key></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #10
0
    def test_conversion_XML_to_JSON_get_list_with_name_of_child(self):
        self.maxDiff = None
        url = "/api/config/car/toyota/models/name-m"
        xml = _collapse_string('''
        <data>
          <car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
            <brand>toyota</brand>
            <models>
              <name-m>name-m</name-m>    
              <capacity>5</capacity>     
            </models>
          </car>
        </data>
        ''')
        #

        expected_json = _collapse_string('''
{"vehicle-a:models" :{"name-m" : "name-m","capacity" : 5}}
        ''')

        schema = load_multiple_schema_root(["vehicle-a","vehicle-augment-a"])

        converter = XmlToJsonTranslator(schema, logger)

        xpath = create_xpath_from_url(url, schema)
        
        actual_json = converter.convert(False, url, xpath, xml)

        actual = _ordered(json.loads(actual_json))
        expected = _ordered(json.loads(expected_json))

        self.assertEquals(actual, expected)
예제 #11
0
    def test_xml_body_2(self):
        self.maxDiff = None
        url = "/api/config/multi-key/key%20part%201,key%20part%202"
        body = _collapse_string(
            """
<multi-key>
  <foo>key part 1</foo>
  <bar>key part 2</bar>
  <treasure>some string</treasure>
</multi-key>
        """
        )

        expected_xml = _collapse_string(
            """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><multi-key xmlns="" xc:operation="replace"><foo>key part 1</foo><bar>key part 2</bar><treasure>some string</treasure></multi-key></config>
        """
        )

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "xml"))

        self.assertEqual(actual_xml, expected_xml)
예제 #12
0
    def test_conversion_post_container_list_2(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/config/top-container-deep"
        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-container-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="create"><a>asdf</a><inner-list-deep><k>asdf</k><inner-container-shallow><a>fdsa</a></inner-container-shallow></inner-list-deep></top-container-deep></config>
        ''')

        body = _collapse_string('''
<top-container-deep>
<a>asdf</a>
<inner-list-deep>
  <k>asdf</k>
    <inner-container-shallow>
    <a>fdsa</a>
  </inner-container-shallow>
</inner-list-deep>
</top-container-deep>
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("POST", url, (body, "xml"))

        self.assertEquals(actual_xml, expected_xml)
예제 #13
0
    def test_json_body_8(self):
        self.maxDiff = None
        url = "/api/config/top-container-deep/inner-container"
        body = _collapse_string('''
{
    "a":"another string",
    "inner-list":[
        {
            "k":"another key thing"
        }
    ]
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-container-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><vehicle-a:inner-container xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">another string</a><inner-list xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">another key thing</k></inner-list></vehicle-a:inner-container></top-container-deep></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body,"json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #14
0
    def test_conversion_post(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/config/top-container-deep/inner-list-shallow"
        expected_xml = _collapse_string(
            """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-container-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><inner-list-shallow xmlns="http://riftio.com/ns/example" xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="create"><k>asdf</k></inner-list-shallow></top-container-deep></config>
        """
        )

        body = _collapse_string(
            """
<inner-list-shallow xmlns="http://riftio.com/ns/example">
        <k>asdf</k>
</inner-list-shallow>
        """
        )

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("POST", url, (body, "xml"))

        self.assertEquals(actual_xml, expected_xml)
예제 #15
0
    def test_conversion_XML_to_JSON_null_string(self):
        self.maxDiff = None
        url = "/api/operational/car/toyota/models"
        xml = _collapse_string('''
        <data>
          <car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
            <models>
              <name-m/>
            </models>
          </car>
        </data>
        ''')

        expected_json = _collapse_string('''
        {"vehicle-a:models":[{"name-m" : ""}]}
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        converter = XmlToJsonTranslator(schema, logger)

        xpath = create_xpath_from_url(url, schema)

        actual_json = converter.convert(False, url, xpath, xml)

        actual = _ordered(json.loads(actual_json))
        expected = _ordered(json.loads(expected_json))

        self.assertEquals(actual, expected)
예제 #16
0
    def test_conversion_XML_to_JSON_get_list_with_name_of_child(self):
        self.maxDiff = None
        url = "/api/config/car/toyota/models/name-m"
        xml = _collapse_string('''
        <data>
          <car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
            <brand>toyota</brand>
            <models>
              <name-m>name-m</name-m>    
              <capacity>5</capacity>     
            </models>
          </car>
        </data>
        ''')
        #

        expected_json = _collapse_string('''
{"vehicle-a:models" :{"name-m" : "name-m","capacity" : 5}}
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        converter = XmlToJsonTranslator(schema, logger)

        xpath = create_xpath_from_url(url, schema)

        actual_json = converter.convert(False, url, xpath, xml)

        actual = _ordered(json.loads(actual_json))
        expected = _ordered(json.loads(expected_json))

        self.assertEquals(actual, expected)
예제 #17
0
    def test_json_body_1(self):
        self.maxDiff = None
        url = "/api/config/top-list-shallow/"
        body = _collapse_string('''
{
  "top-list-shallow"  :
  [
    {
      "k" : "some key 1"
    },
    {
      "k" : "some key 2"
    }

  ]
}

        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-list-shallow xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some key 1</k></top-list-shallow><top-list-shallow xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some key 2</k></top-list-shallow></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body,"json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #18
0
    def test_xml_body_3(self):
        self.maxDiff = None
        url = "/api/config/top-list-deep"
        body = _collapse_string('''
<top-list-deep>
  <k>some key<k>
  <inner-list>
    <k>some other key</k?
    <a>some string</a>
    <inner-container>
      <a>some other string</a>
    </inner-container>      
  </inner-list>
  <inner-container-shallow>
    <a>yet a third string</a>
  </inner-container-shallow>    
  <inner-container-deep>
    <bottom-list-shallow>
      <k>yet a third key</a>
    </bottom-list-shallow>
  </inner-container-deep>    
</top-list-deep>
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-list-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><k>some key<k><inner-list><k>some other key</k?<a>some string</a><inner-container><a>some other string</a></inner-container></inner-list><inner-container-shallow><a>yet a third string</a></inner-container-shallow><inner-container-deep><bottom-list-shallow><k>yet a third key</a></bottom-list-shallow></inner-container-deep></top-list-deep></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body,"xml"))

        self.assertEqual(actual_xml, expected_xml)
예제 #19
0
    def test_conversion_XML_to_JSON_version(self):
        self.maxDiff = None
        url = "/api/config/car/toyota/models"
        xml = _collapse_string('''
<data>
          <car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
            <models>
              <name-m>Camry</name-m>	  
              <year>2015</year>	  
              <capacity>5</capacity>	  
              <version_str>2.0</version_str>
            </models>
          </car>
        </data>
        ''')
        #

        expected_json = _collapse_string('''
{"vehicle-a:models":[{"year" : 2015,"name-m" : "Camry","capacity" : 5, "version_str":"2.0"}]}
        ''')

        schema = load_multiple_schema_root(["vehicle-a","vehicle-augment-a"])

        converter = XmlToJsonTranslator(schema, logger)

        xpath = create_xpath_from_url(url, schema)
        
        actual_json = converter.convert(False, url, xpath, xml)

        actual = _ordered(json.loads(actual_json))
        expected = _ordered(json.loads(expected_json))

        self.assertEquals(actual, expected)
예제 #20
0
    def test_json_body_11(self):
        self.maxDiff = None
        url = "/api/config/misc"
        body = _collapse_string('''
{
    "bool-leaf":true,
    "empty-leaf":[null],
    "enum-leaf":"a",
    "int-leaf":42,
    "list-a":[
        {
            "id":0,
            "foo":"asdf"
        }
    ],
    "list-b":[
        {
            "id":0
        }
    ],
    "numbers":[
        {
            "int8-leaf":0,
            "int16-leaf":0,
            "int32-leaf":0,
            "int64-leaf":0,
            "uint8-leaf":0,
            "uint16-leaf":0,
            "uint32-leaf":0,
            "uint64-leaf":0,
            "decimal-leaf":0
        },
        {
            "int8-leaf":"1",
            "int16-leaf":"0",
            "int32-leaf":"0",
            "int64-leaf":"0",
            "uint8-leaf":"0",
            "uint16-leaf":"0",
            "uint32-leaf":"0",
            "uint64-leaf":"0",
            "decimal-leaf":"0"
        }
    ]
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><vehicle-a:misc xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><bool-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace">true</bool-leaf><empty-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"></empty-leaf><enum-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">a</enum-leaf><int-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">42</int-leaf><list-a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><id xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</id><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</foo></list-a><list-b xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><id xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</id></list-b><numbers xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><int8-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int8-leaf><int16-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int16-leaf><int32-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int32-leaf><int64-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int64-leaf><uint8-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint8-leaf><uint16-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint16-leaf><uint32-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint32-leaf><uint64-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint64-leaf><decimal-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</decimal-leaf></numbers><numbers xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><int8-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1</int8-leaf><int16-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int16-leaf><int32-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int32-leaf><int64-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int64-leaf><uint8-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint8-leaf><uint16-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint16-leaf><uint32-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint32-leaf><uint64-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint64-leaf><decimal-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</decimal-leaf></numbers></vehicle-a:misc></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #21
0
    def test_json_body_11(self):
        self.maxDiff = None
        url = "/api/config/misc"
        body = _collapse_string('''
{
    "bool-leaf":true,
    "empty-leaf":[null],
    "enum-leaf":"a",
    "int-leaf":42,
    "list-a":[
        {
            "id":0,
            "foo":"asdf"
        }
    ],
    "list-b":[
        {
            "id":0
        }
    ],
    "numbers":[
        {
            "int8-leaf":0,
            "int16-leaf":0,
            "int32-leaf":0,
            "int64-leaf":0,
            "uint8-leaf":0,
            "uint16-leaf":0,
            "uint32-leaf":0,
            "uint64-leaf":0,
            "decimal-leaf":0
        },
        {
            "int8-leaf":"1",
            "int16-leaf":"0",
            "int32-leaf":"0",
            "int64-leaf":"0",
            "uint8-leaf":"0",
            "uint16-leaf":"0",
            "uint32-leaf":"0",
            "uint64-leaf":"0",
            "decimal-leaf":"0"
        }
    ]
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><vehicle-a:misc xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><bool-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">true</bool-leaf><empty-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"></empty-leaf><enum-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">a</enum-leaf><int-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">42</int-leaf><list-a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><id xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</id><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</foo></list-a><list-b xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><id xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</id></list-b><numbers xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><int8-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int8-leaf><int16-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int16-leaf><int32-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int32-leaf><int64-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int64-leaf><uint8-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint8-leaf><uint16-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint16-leaf><uint32-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint32-leaf><uint64-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint64-leaf><decimal-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</decimal-leaf></numbers><numbers xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><int8-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1</int8-leaf><int16-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int16-leaf><int32-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int32-leaf><int64-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</int64-leaf><uint8-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint8-leaf><uint16-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint16-leaf><uint32-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint32-leaf><uint64-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</uint64-leaf><decimal-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</decimal-leaf></numbers></vehicle-a:misc></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body,"json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #22
0
    def test_conversion_url_to_dts_xpath_2(self):
        self.maxDiff = None
        url = "/api/running/rwrestconf-configuration/"  # trailing / on purpose
        expected = ""

        schema = load_multiple_schema_root(["rw-restconf"])

        actual = create_dts_xpath_from_url(url, schema)

        value = RwKeyspec.path_from_xpath(RwRestconfYang.get_schema(), actual, RwKeyspec.RwXpathType.KEYSPEC, None)
예제 #23
0
    def test_json_body_4(self):
        self.maxDiff = None
        url = "/api/config/top-container-deep"
        body = _collapse_string(
            """
{
    "a":"some kind of string",
    "inner-list-shallow":[
        {
            "k":"some key thing"
        },
        {
            "k":"some other key thing"
        }
    ],
    "inner-container":{
        "a":"another string",
        "inner-list":[
            {
                "k":"another key thing"
            }
        ]
    },
    "inner-list-deep":[
        {
            "k":"inner key",
            "inner-container-shallow":{
                "a":"an inner string"
            },
            "inner-container-deep":{
                "bottom-list-shallow":[
                    {
                        "k":"bottom key"
                    }
                ]
            }
        }
    ]
}
        """
        )

        expected_xml = _collapse_string(
            """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><vehicle-a:top-container-deep xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace">some kind of string</a><inner-list-shallow xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some key thing</k></inner-list-shallow><inner-list-shallow xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some other key thing</k></inner-list-shallow><inner-container xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">another string</a><inner-list xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">another key thing</k></inner-list></inner-container><inner-list-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">inner key</k><inner-container-shallow xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">an inner string</a></inner-container-shallow><inner-container-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><bottom-list-shallow xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">bottom key</k></bottom-list-shallow></inner-container-deep></inner-list-deep></vehicle-a:top-container-deep></config>
        """
        )

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #24
0
    def test_dts_xpath_multi_key(self):
        self.maxDiff = None
        url = "/api/config/multi-key/k1,k2"

        expected_xpath = "C,/vehicle-a:multi-key[foo = 'k1'][bar = 'k2']"

        schema = load_multiple_schema_root(["vehicle-a"])

        actual_xpath = create_dts_xpath_from_url(url, schema)

        self.assertEquals(actual_xpath, expected_xpath)
예제 #25
0
    def test_dts_xpath_multi_key(self):
        self.maxDiff = None
        url = "/api/config/multi-key/k1,k2"

        expected_xpath = "C,/vehicle-a:multi-key[foo = 'k1'][bar = 'k2']"

        schema = load_multiple_schema_root(["vehicle-a"])

        actual_xpath = create_dts_xpath_from_url(url, schema)

        self.assertEquals(actual_xpath, expected_xpath)
예제 #26
0
    def test_conversion_url_to_dts_xpath_2(self):
        self.maxDiff = None
        url = "/api/running/rwrestconf-configuration/"  # trailing / on purpose
        expected = ""

        schema = load_multiple_schema_root(["rw-restconf"])

        actual = create_dts_xpath_from_url(url, schema)

        value = RwKeyspec.path_from_xpath(RwRestconfYang.get_schema(), actual,
                                          RwKeyspec.RwXpathType.KEYSPEC, None)
예제 #27
0
    def test_conversion_url_to_dts_xpath(self):
        self.maxDiff = None
        url = "/api/operational/car/toyota/models"
        expected = ""

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        actual = create_dts_xpath_from_url(url, schema)

        xpath = "D,/vehicle-a:car[vehicle-a:key_name = 'toyota']"
        value = RwKeyspec.path_from_xpath(VehicleAYang.get_schema(), actual, RwKeyspec.RwXpathType.KEYSPEC, None)
예제 #28
0
    def test_conversion_url_to_dts_xpath(self):
        self.maxDiff = None
        url = "/api/operational/car/toyota/models"
        expected = ""

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        actual = create_dts_xpath_from_url(url, schema)

        xpath = "D,/vehicle-a:car[vehicle-a:key_name = 'toyota']"
        value = RwKeyspec.path_from_xpath(VehicleAYang.get_schema(), actual,
                                          RwKeyspec.RwXpathType.KEYSPEC, None)
예제 #29
0
    def test_conversion_CONFD_URL_to_XML_get_list_key(self):
        self.maxDiff = None # expected_xml is too large

        url = "/api/operational/car/honda"
        expected_xml = _collapse_string('''
<data><vehicle-a:car xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><brand>honda</brand></vehicle-a:car></data>
        ''')

        schema = load_multiple_schema_root(["vehicle-a","vehicle-augment-a"])

        actual_xml = convert_get_request_to_xml(schema, url) 

        self.assertEquals(actual_xml, expected_xml)
예제 #30
0
    def test_conversion_CONFD_URL_to_XML_get_list_key(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/operational/car/honda"
        expected_xml = _collapse_string('''
<data><vehicle-a:car xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><brand>honda</brand></vehicle-a:car></data>
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        actual_xml = convert_get_request_to_xml(schema, url)

        self.assertEquals(actual_xml, expected_xml)
예제 #31
0
    def test_conversion_CONFD_URL_to_XML_00(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/config/top-container-deep"
        expected_xml = _collapse_string('''
<data>
  <vehicle-a:top-container-deep xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"/>
</data>
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        actual_xml = convert_get_request_to_xml(schema, url)

        self.compare_doms(actual_xml, expected_xml)
예제 #32
0
    def test_conversion_CONFD_URL_to_XML_delete_list_key(self):
        self.maxDiff = None # expected_xml is too large

        url = "/api/operational/top-container-deep/inner-container/inner-list/some-key"
        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-container-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><inner-container xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><inner-list xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="delete"><k>some-key</k></inner-list></inner-container></top-container-deep></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a","vehicle-augment-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("DELETE", url, None)

        self.assertEquals(actual_xml, expected_xml)
예제 #33
0
    def test_conversion_CONFD_URL_to_XML_00(self):
        self.maxDiff = None # expected_xml is too large

        url = "/api/config/top-container-deep"
        expected_xml = _collapse_string('''
<data>
  <vehicle-a:top-container-deep xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"/>
</data>
        ''')

        schema = load_multiple_schema_root(["vehicle-a","vehicle-augment-a"])

        actual_xml = convert_get_request_to_xml(schema, url)

        self.compare_doms(actual_xml, expected_xml)
예제 #34
0
    def test_conversion_CONFD_URL_to_XML_delete_list_key(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/operational/top-container-deep/inner-container/inner-list/some-key"
        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-container-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><inner-container xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><inner-list xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="delete"><k>some-key</k></inner-list></inner-container></top-container-deep></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("DELETE", url, None)

        self.assertEquals(actual_xml, expected_xml)
예제 #35
0
    def test_conversion_XML_to_JSON_vcs(self):
        self.maxDiff = None
        url = "/api/operational/vcs/info"
        xml = _collapse_string(
            """
<data>
<rw-base:vcs xmlns:rw-base="http://riftio.com/ns/riftware-1.0/rw-base">
    <rw-base:info>
        <rw-base:components>
            <rw-base:component_info>
                <rw-base:instance_name>RW_VM_MASTER-2</rw-base:instance_name>
                <rw-base:component_type>RWVM</rw-base:component_type>
                <rw-base:component_name>RW_VM_MASTER</rw-base:component_name>
                <rw-base:instance_id>2</rw-base:instance_id>
                <rw-base:state>RUNNING</rw-base:state>
                <rw-base:config-ready>true</rw-base:config-ready>
                <rw-base:recovery-action>FAILCRITICAL</rw-base:recovery-action>
                <rw-base:rwcomponent_parent>rw.colony-102</rw-base:rwcomponent_parent>
                <rw-base:rwcomponent_children>msgbroker-100</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>dtsrouter-101</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.Proc_1.uAgent-103</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.TermIO-105</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.CLI-104</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.Proc_2.Restconf-106</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.Proc_3.RestPortForward-108</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.MC.UI-109</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>logd-110</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>confd-114</rw-base:rwcomponent_children>
                <rw-base:vm_info>
                    <rw-base:vm-ip-address>127.0.2.1</rw-base:vm-ip-address>
                    <rw-base:pid>31610</rw-base:pid>
                    <rw-base:leader>true</rw-base:leader>
                </rw-base:vm_info>
            </rw-base:component_info>
        </rw-base:components>
    </rw-base:info>
</rw-base:vcs>
</data>
        """
        )

        schema = load_multiple_schema_root(["rw-base"])

        converter = XmlToJsonTranslator(schema, logger)

        xpath = create_xpath_from_url(url, schema)

        actual_json = converter.convert(False, url, xpath, xml)
예제 #36
0
    def test_conversion_CONFD_URL_to_XML_get_bogus(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/operational/bogus"

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        converter = ConfdRestTranslator(schema)

        caught_exception = False
        try:
            actual_xml = convert_get_request_to_xml(schema, url)
        except ValueError:
            caught_exception = True

        self.assertTrue(caught_exception)
예제 #37
0
    def test_conversion_CONFD_URL_to_XML_3(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/operational/car/subaru/extras?select=speakers;engine(*)"
        expected_xml = _collapse_string(
            """
<data><vehicle-a:car xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><brand>subaru</brand><vehicle-augment-a:extras xmlns:vehicle-augment-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-augment-a"/></vehicle-a:car></data>

        """
        )

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        actual_xml = convert_get_request_to_xml(schema, url)

        self.assertEquals(actual_xml, expected_xml)
예제 #38
0
    def test_conversion_CONFD_URL_to_XML_get_bogus(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/operational/bogus"

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        converter = ConfdRestTranslator(schema)

        caught_exception = False
        try:
            actual_xml = convert_get_request_to_xml(schema, url)
        except ValueError:
            caught_exception = True

        self.assertTrue(caught_exception)
예제 #39
0
    def test_conversion_XML_to_JSON_vcs(self):
        self.maxDiff = None
        url = "/api/operational/vcs/info"
        xml = _collapse_string('''
<data>
<rw-base:vcs xmlns:rw-base="http://riftio.com/ns/riftware-1.0/rw-base">
    <rw-base:info>
        <rw-base:components>
            <rw-base:component_info>
                <rw-base:instance_name>RW_VM_MASTER-2</rw-base:instance_name>
                <rw-base:component_type>RWVM</rw-base:component_type>
                <rw-base:component_name>RW_VM_MASTER</rw-base:component_name>
                <rw-base:instance_id>2</rw-base:instance_id>
                <rw-base:state>RUNNING</rw-base:state>
                <rw-base:config-ready>true</rw-base:config-ready>
                <rw-base:recovery-action>FAILCRITICAL</rw-base:recovery-action>
                <rw-base:rwcomponent_parent>rw.colony-102</rw-base:rwcomponent_parent>
                <rw-base:rwcomponent_children>msgbroker-100</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>dtsrouter-101</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.Proc_1.uAgent-103</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.TermIO-105</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.CLI-104</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.Proc_2.Restconf-106</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.Proc_3.RestPortForward-108</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>RW.MC.UI-109</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>logd-110</rw-base:rwcomponent_children>
                <rw-base:rwcomponent_children>confd-114</rw-base:rwcomponent_children>
                <rw-base:vm_info>
                    <rw-base:vm-ip-address>127.0.2.1</rw-base:vm-ip-address>
                    <rw-base:pid>31610</rw-base:pid>
                    <rw-base:leader>true</rw-base:leader>
                </rw-base:vm_info>
            </rw-base:component_info>
        </rw-base:components>
    </rw-base:info>
</rw-base:vcs>
</data>
        ''')

        schema = load_multiple_schema_root(["rw-base"])

        converter = XmlToJsonTranslator(schema, logger)

        xpath = create_xpath_from_url(url, schema)

        actual_json = converter.convert(False, url, xpath, xml)
예제 #40
0
    def test_get_cross_namespace(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/config/car/honda%20motors/extras"
        expected_xml = _collapse_string('''
<data>
  <vehicle-a:car xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
    <brand>honda motors</brand>
    <vehicle-augment-a:extras xmlns:vehicle-augment-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-augment-a"/>
  </vehicle-a:car>
</data>
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        actual_xml = convert_get_request_to_xml(schema, url)

        self.compare_doms(actual_xml, expected_xml)
예제 #41
0
    def test_get_cross_namespace(self):
        self.maxDiff = None # expected_xml is too large

        url = "/api/config/car/honda%20motors/extras"
        expected_xml = _collapse_string('''
<data>
  <vehicle-a:car xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
    <brand>honda motors</brand>
    <vehicle-augment-a:extras xmlns:vehicle-augment-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-augment-a"/>
  </vehicle-a:car>
</data>
        ''')

        schema = load_multiple_schema_root(["vehicle-a","vehicle-augment-a"])

        actual_xml = convert_get_request_to_xml(schema, url)

        self.compare_doms(actual_xml, expected_xml)
예제 #42
0
    def test_conversion_CONFD_URL_to_XML_25(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/config/multi-key/firstkey,secondkey/treasure"
        expected_xml = _collapse_string('''
<data>
  <vehicle-a:multi-key xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
    <foo>firstkey</foo>
    <bar>secondkey</bar>
    <vehicle-a:treasure/>
  </vehicle-a:multi-key>
</data>
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        actual_xml = convert_get_request_to_xml(schema, url)

        self.compare_doms(actual_xml, expected_xml)
예제 #43
0
    def test_conversion_CONFD_URL_to_XML_delete_list_key_simple(self):
        self.maxDiff = None # expected_xml is too large

        url = "/api/operational/car/honda"
        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
  <car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="delete">
    <brand>honda</brand>
  </car>
</config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a","vehicle-augment-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("DELETE", url, None)

        self.assertEquals(actual_xml, expected_xml)
예제 #44
0
    def test_conversion_CONFD_URL_to_XML_25(self):
        self.maxDiff = None # expected_xml is too large

        url = "/api/config/multi-key/firstkey,secondkey/treasure"
        expected_xml = _collapse_string('''
<data>
  <vehicle-a:multi-key xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">
    <foo>firstkey</foo>
    <bar>secondkey</bar>
    <vehicle-a:treasure/>
  </vehicle-a:multi-key>
</data>
        ''')

        schema = load_multiple_schema_root(["vehicle-a","vehicle-augment-a"])

        actual_xml = convert_get_request_to_xml(schema, url)

        self.compare_doms(actual_xml, expected_xml)
예제 #45
0
    def test_conversion_CONFD_URL_to_XML_delete_list_key_simple(self):
        self.maxDiff = None  # expected_xml is too large

        url = "/api/operational/car/honda"
        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
  <car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="delete">
    <brand>honda</brand>
  </car>
</config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("DELETE", url, None)

        self.assertEquals(actual_xml, expected_xml)
예제 #46
0
    def test_json_body_10(self):
        self.maxDiff = None
        url = "/api/config/misc"
        body = _collapse_string('''
{
        "empty-leaf" : [null]
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><vehicle-a:misc xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><empty-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"></empty-leaf></vehicle-a:misc></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body,"json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #47
0
    def test_json_body_serialized_list_element(self):
        self.maxDiff = None
        url = "/api/config/misc/list-a/0"
        model = RwYang.model_create_libncx()
        model.load_schema_ypbc(VehicleAYang.get_schema())
        list_a_msg = VehicleAYang.YangData_VehicleA_Misc_ListA(id=0, foo="asdf")
        list_a_json = list_a_msg.to_json(model)
        body = _collapse_string(list_a_json)

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><misc xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><list-a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><id xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</id><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</foo></list-a></misc></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #48
0
    def test_xml_body_0(self):
        self.maxDiff = None
        url = "/api/config/top-container-shallow"
        body = _collapse_string('''
<top-container-shallow>
  <a>some leaf 0</a>
</top-container-shallow>
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-container-shallow xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><a>some leaf 0</a></top-container-shallow></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body,"xml"))
        
        self.assertEqual(actual_xml, expected_xml)
예제 #49
0
    def test_json_body_0(self):
        self.maxDiff = None
        url = "/api/config/top-container-shallow"
        body = _collapse_string('''
{
  "a" : "some leaf 0"
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><vehicle-a:top-container-shallow xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">some leaf 0</a></vehicle-a:top-container-shallow></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body,"json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #50
0
    def test_xml_body_4(self):
        self.maxDiff = None
        url = "/api/config/top-list-deep/key1/inner-list/key2"
        body = _collapse_string('''
<inner-list>
  <k>key2</k>
</inner-list>
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-list-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k>key1</k><inner-list xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><k>key2</k></inner-list></top-list-deep></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body,"xml"))

        self.assertEqual(actual_xml, expected_xml)
예제 #51
0
    def test_json_body_0(self):
        self.maxDiff = None
        url = "/api/config/top-container-shallow"
        body = _collapse_string('''
{
  "a" : "some leaf 0"
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><vehicle-a:top-container-shallow xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace">some leaf 0</a></vehicle-a:top-container-shallow></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #52
0
    def test_json_body_10(self):
        self.maxDiff = None
        url = "/api/config/misc"
        body = _collapse_string('''
{
        "empty-leaf" : [null]
}
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><vehicle-a:misc xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><empty-leaf xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"></empty-leaf></vehicle-a:misc></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #53
0
    def test_xml_body_4(self):
        self.maxDiff = None
        url = "/api/config/top-list-deep/key1/inner-list/key2"
        body = _collapse_string('''
<inner-list>
  <k>key2</k>
</inner-list>
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-list-deep xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k>key1</k><inner-list xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><k>key2</k></inner-list></top-list-deep></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "xml"))

        self.assertEqual(actual_xml, expected_xml)
예제 #54
0
    def test_xml_body_1(self):
        self.maxDiff = None
        url = "/api/config/top-list-shallow/some%20key%201"
        body = _collapse_string('''
<top-list-shallow xmlns="http://riftio.com/ns/example">
   <k xmlns="http://riftio.com/ns/example">some key 1</k>
</top-list-shallow>
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><top-list-shallow xmlns="http://riftio.com/ns/example" xmlns="" xc:operation="replace"><k xmlns="http://riftio.com/ns/example">some key 1</k></top-list-shallow></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "xml"))

        self.assertEqual(actual_xml, expected_xml)
예제 #55
0
    def test_json_body_serialized_list_element(self):
        self.maxDiff = None
        url = "/api/config/misc/list-a/0"
        model = RwYang.model_create_libncx()
        model.load_schema_ypbc(VehicleAYang.get_schema())
        list_a_msg = VehicleAYang.YangData_VehicleA_Misc_ListA(id=0,
                                                               foo="asdf")
        list_a_json = list_a_msg.to_json(model)
        body = _collapse_string(list_a_json)

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><misc xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><list-a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><id xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</id><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</foo></list-a></misc></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
예제 #56
0
    def test_xml_body_2(self):
        self.maxDiff = None
        url = "/api/config/multi-key/key%20part%201,key%20part%202"
        body = _collapse_string('''
<multi-key>
  <foo>key part 1</foo>
  <bar>key part 2</bar>
  <treasure>some string</treasure>
</multi-key>
        ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><multi-key xmlns="" xc:operation="replace"><foo>key part 1</foo><bar>key part 2</bar><treasure>some string</treasure></multi-key></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "xml"))

        self.assertEqual(actual_xml, expected_xml)
예제 #57
0
    def test_parse_message(self):
        logger = logging.getLogger(__name__)
        self.maxDiff = None  # expected string is too large

        message = '''
        {
            "path":"/car/audi",
            "fields":{
                "bogus":"bogus",
                "bogus":"bogus"
            },
            "channel":"test_rest"
        }
        '''

        expected_xpath = 'D,/vehicle-a:car[vehicle-a:brand="audi"]'

        schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"])

        subscription_parser = SubscriptionParser(logger, schema)

        actual_xpath = subscription_parser.parse(message)

        self.assertEquals(actual_xpath, expected_xpath)