Exemple #1
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)
Exemple #2
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)
Exemple #3
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)
Exemple #4
0
    def test_conversion_PUT_JSON_to_XML_list_with_escaped_url(self):
        self.maxDiff = None

        url = '/api/config/car/subaru%252F1%252F1/models/WRX/'
        json = _collapse_string('''
{
            "models":{
                "name-m":"WRX",
                "year":2015,
                "capacity":5,
                "is-cool":"True"
            }


}
       ''')

        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"><brand>subaru/1/1</brand><models xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><name-m xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">WRX</name-m><year xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">2015</year><capacity xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">5</capacity><is-cool xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">true</is-cool></models></car></config>
        ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("PUT", url, (json,"application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Exemple #5
0
    def test_conversion_POST_JSON_to_XML_rpc_with_list_input(self):
        self.maxDiff = None

        url = "/api/operations/in-list-no-out"
        json = _collapse_string(
            """
{
  "input" : 
    {
        "in" :
          [
        {"k" : "asdf"},
        {"k" : "fdsa"}
          ]
    }
}
        """
        )

        expected_xml = _collapse_string(
            """
<vehicle-a:in-list-no-out xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><in xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</k></in><in xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">fdsa</k></in></vehicle-a:in-list-no-out>

       """
        )

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url, (json, "application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Exemple #6
0
    def test_conversion_POST_JSON_to_XML_rpc_negative(self):
        self.maxDiff = None

        url = "/api/operations/in-list-no-out"
        json = _collapse_string(
            """
{
  "input" : 
    {
"extra":"asdf"
    }
}
        """
        )

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        caught = False
        try:
            actual_xml = converter.convert("POST", url, (json, "application/data+json"))
        except ValueError:
            caught = True
        self.assertEquals(True, caught)
Exemple #7
0
    def test_conversion_PUT_JSON_to_XML_1(self):
        self.maxDiff = None

        url = '/api/config/car'
        json = _collapse_string('''
{
    "car":[
        {
            "brand":"subaru",
            "models":{
                "name-m":"WRX",
                "year":2015,
                "capacity":5,
                "is-cool":"True"
            }
        }
    ]
}
       ''')

        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="replace"><brand xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">subaru</brand><models xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name-m xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">WRX</name-m><year xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">2015</year><capacity xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">5</capacity><is-cool xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">true</is-cool></models></car></config>
        ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("PUT", url,
                                       (json, "application/data+json"))

        self.compare_doms(actual_xml, expected_xml)
Exemple #8
0
    def test_conversion_PUT_JSON_to_XML_1(self):
        self.maxDiff = None

        url = "/api/config/car"
        json = _collapse_string(
            """
{
    "car":[
        {
            "brand":"subaru",
            "models":{
                "name-m":"WRX",
                "year":2015,
                "capacity":5,
                "is-cool":"True"
            }
        }
    ]
}
       """
        )

        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="replace"><brand xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">subaru</brand><models xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name-m xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">WRX</name-m><year xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">2015</year><capacity xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">5</capacity><is-cool xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">true</is-cool></models></car></config>
        """
        )

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("PUT", url, (json, "application/data+json"))

        self.compare_doms(actual_xml, expected_xml)
Exemple #9
0
    def test_conversion_POST_JSON_to_XML_rpc_with_list_input(self):
        self.maxDiff = None

        url = '/api/operations/in-list-no-out'
        json = _collapse_string('''
{
  "input" : 
    {
        "in" :
          [
        {"k" : "asdf"},
        {"k" : "fdsa"}
          ]
    }
}
        ''')

        expected_xml = _collapse_string('''
<vehicle-a:in-list-no-out xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><in xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</k></in><in xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">fdsa</k></in></vehicle-a:in-list-no-out>

       ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url,
                                       (json, "application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Exemple #10
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)
Exemple #11
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)
Exemple #12
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)
Exemple #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" 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)
Exemple #14
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)
Exemple #15
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)
Exemple #16
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)
Exemple #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"><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)
Exemple #18
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)
Exemple #19
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)
Exemple #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)
Exemple #21
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)
Exemple #22
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)
Exemple #23
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)
Exemple #24
0
    def test_conversion_PUT_JSON_to_XML_199(self):
        self.maxDiff = None

        url = '/api/running/rwrestconf-configuration/log-timing'
        json = _collapse_string('''
{"log-timing" : "True"
}

       ''')

        root = load_schema_root("rw-restconf")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url, (json,"application/data+json"))
Exemple #25
0
    def test_conversion_PUT_JSON_to_XML_199(self):
        self.maxDiff = None

        url = '/api/running/rwrestconf-configuration/log-timing'
        json = _collapse_string('''
{"log-timing" : "True"
}

       ''')

        root = load_schema_root("rw-restconf")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url,
                                       (json, "application/data+json"))
Exemple #26
0
    def test_conversion_POST_JSON_to_XML_asdf(self):
        self.maxDiff = None

        url = "/api/operations/exec-ns-config-primitive"
        json = _collapse_string(
            """
{
    "input":{
        "vehicle-a:name":"create-user",
        "vehicle-a:nsr_id_ref":"1181c5ce-9c8b-4e1d-9247-2a38cdf128bb",
        "vehicle-a:vnf-primitive-group":[
            {
                "member-vnf-index-ref":"1",
                "vnfr-id-ref":"76d116e8-cf66-11e5-841e-6cb3113b406f",
                "primitive":[
                    {
                        "name":"number",
                        "value":"123"
                    },
                    {
                        "name":"password",
                        "value":"letmein"
                    }
                ]
            }
        ]
    }
}
        """
        )

        expected_xml = _collapse_string(
            """
<vehicle-a:exec-ns-config-primitive xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">create-user</name><nsr_id_ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1181c5ce-9c8b-4e1d-9247-2a38cdf128bb</nsr_id_ref><vnf-primitive-group xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><member-vnf-index-ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1</member-vnf-index-ref><vnfr-id-ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">76d116e8-cf66-11e5-841e-6cb3113b406f</vnfr-id-ref><primitive xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">number</name><value xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">123</value></primitive><primitive xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">password</name><value xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">letmein</value></primitive></vnf-primitive-group></vehicle-a:exec-ns-config-primitive>
        """
        )

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url, (json, "application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Exemple #27
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)
Exemple #28
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)
Exemple #29
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)
Exemple #30
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)
Exemple #31
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)
Exemple #32
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)
Exemple #33
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)
Exemple #34
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)
Exemple #35
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)
Exemple #36
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)
Exemple #37
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)
Exemple #38
0
    def test_conversion_POST_JSON_to_XML_asdf(self):
        self.maxDiff = None

        url = '/api/operations/exec-ns-config-primitive'
        json = _collapse_string('''
{
    "input":{
        "vehicle-a:name":"create-user",
        "vehicle-a:nsr_id_ref":"1181c5ce-9c8b-4e1d-9247-2a38cdf128bb",
        "vehicle-a:vnf-primitive-group":[
            {
                "member-vnf-index-ref":"1",
                "vnfr-id-ref":"76d116e8-cf66-11e5-841e-6cb3113b406f",
                "primitive":[
                    {
                        "name":"number",
                        "value":"123"
                    },
                    {
                        "name":"password",
                        "value":"letmein"
                    }
                ]
            }
        ]
    }
}
        ''')

        expected_xml = _collapse_string('''
<vehicle-a:exec-ns-config-primitive xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">create-user</name><nsr_id_ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1181c5ce-9c8b-4e1d-9247-2a38cdf128bb</nsr_id_ref><vnf-primitive-group xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><member-vnf-index-ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1</member-vnf-index-ref><vnfr-id-ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">76d116e8-cf66-11e5-841e-6cb3113b406f</vnfr-id-ref><primitive xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">number</name><value xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">123</value></primitive><primitive xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">password</name><value xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">letmein</value></primitive></vnf-primitive-group></vehicle-a:exec-ns-config-primitive>
        ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url,
                                       (json, "application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Exemple #39
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)
Exemple #40
0
    def test_conversion_post_container_list_3(self):
        self.maxDiff = None # expected_xml is too large

        url = "/api/config/top-container-deep/inner-container"
        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" xc:operation="create"><a>fdsa</a></inner-container></top-container-deep></config>
        ''')

        body = _collapse_string('''
<inner-container>
  <a>fdsa</a>
</inner-container>
        ''')

        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)
Exemple #41
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)
Exemple #42
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"))

        print(actual_xml)
        print(expected_xml)

        self.assertEqual(actual_xml, expected_xml)
Exemple #43
0
    def test_conversion_POST_JSON_to_XML_rpc_negative(self):
        self.maxDiff = None

        url = '/api/operations/in-list-no-out'
        json = _collapse_string('''
{
  "input" : 
    {
"extra":"asdf"
    }
}
        ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        caught = False
        try:
            actual_xml = converter.convert("POST", url,
                                           (json, "application/data+json"))
        except ValueError:
            caught = True
        self.assertEquals(True, caught)
Exemple #44
0
    def test_json_body_9(self):
        self.maxDiff = None
        url = "/api/config/top-list-deep/some%20key/inner-container-shallow"
        body = _collapse_string(
            """
{
    "a" : "yet a third string"
}
        """
        )

        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>some key</k><vehicle-a:inner-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">yet a third string</a></vehicle-a:inner-container-shallow></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)
Exemple #45
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)
Exemple #46
0
    def _start_server(self):
        if self._server is not None:
            self._server.stop()
        self._connection_manager = ConnectionManager(
            self._configuration, self._log, self.loop, self.NETCONF_SERVER_IP,
            self.NETCONF_SERVER_PORT, self._dts, self._schema_root)
        self._confd_url_converter = ConfdRestTranslator(self._schema_root)
        self._xml_to_json_translator = XmlToJsonTranslator(
            self._schema_root, self._log)

        webhost = "{}:{}".format(socket.gethostbyname(socket.getfqdn()),
                                 self.RESTCONF_PORT)
        self._state_provider = StateProvider(self._log, self.loop,
                                             self.NETCONF_SERVER_IP,
                                             self.NETCONF_SERVER_PORT, webhost,
                                             self._configuration.use_https)

        http_handler_arguments = {
            "asyncio_loop": self.loop,
            "confd_url_converter": self._confd_url_converter,
            "configuration": self._configuration,
            "connection_manager": self._connection_manager,
            "logger": self._log,
            "schema_root": self._schema_root,
            "statistics": self._statistics,
            "xml_to_json_translator": self._xml_to_json_translator,
        }
        stream_handler_args = {
            "logger": self._log,
            "loop": self.loop,
            "netconf_ip": self.NETCONF_SERVER_IP,
            "netconf_port": self.NETCONF_SERVER_PORT,
            "statistics": self._statistics,
            "xml_to_json_translator": self._xml_to_json_translator,
        }
        logout_handler_arguments = {
            "logger": self._log,
            "connection_manager": self._connection_manager,
            "asyncio_loop": self.loop,
        }

        # provide a read-only handler that always uses the xml-mode for speed
        self._read_only_configuration = Configuration()
        self._read_only_configuration.use_netconf = False
        self._read_only_connection_manager = ConnectionManager(
            self._configuration, self._log, self.loop, self.NETCONF_SERVER_IP,
            self.NETCONF_SERVER_PORT, self._dts, self._schema_root)
        read_only_handler_arguments = {
            "logger": self._log,
            "connection_manager": self._read_only_connection_manager,
            "schema_root": self._schema_root,
            "confd_url_converter": self._confd_url_converter,
            "xml_to_json_translator": self._xml_to_json_translator,
            "asyncio_loop": self.loop,
            "configuration": self._configuration,
            "statistics": self._statistics,
        }

        application = tornado.web.Application([
            (r"/api/readonly/config/(.*)", ReadOnlyHandler,
             read_only_handler_arguments),
            (r"/api/readonly/running/(.*)", ReadOnlyHandler,
             read_only_handler_arguments),
            (r"/api/readonly/operational/(.*)", ReadOnlyHandler,
             read_only_handler_arguments),
            (r"/api/config/(.*)", HttpHandler, http_handler_arguments),
            (r"/api/logout", LogoutHandler, logout_handler_arguments),
            (r"/api/operational/(.*)", HttpHandler, http_handler_arguments),
            (r"/api/operations/(.*)", HttpHandler, http_handler_arguments),
            (r"/api/running/(.*)", HttpHandler, http_handler_arguments),
            (r"/api/schema/(.*)", HttpHandler, http_handler_arguments),
            (r"/streams/(.*)", event_source.HttpStreamHandler,
             stream_handler_args),
            (r"/ws_streams/(.*)", event_source.WebSocketStreamHandler,
             stream_handler_args),
        ],
                                              compress_response=True)

        io_loop = rift.tasklets.tornado.TaskletAsyncIOLoop(
            asyncio_loop=self.loop)
        if self._configuration.use_https:
            ssl_options = {
                "certfile": self._ssl_cert,
                "keyfile": self._ssl_key,
            }
            self._server = tornado.httpserver.HTTPServer(
                application,
                io_loop=io_loop,
                ssl_options=ssl_options,
            )
        else:
            self._server = tornado.httpserver.HTTPServer(
                application,
                io_loop=io_loop,
            )

        self._server.listen(self.RESTCONF_PORT)