-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cfggen] Add basic functional test (#375)
[cfggen] Add basic functional test
- Loading branch information
Showing
8 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
recursive-include platform *.json *.ini *.conf | ||
recursive-include tests *.j2 *.yml *.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<DeviceMiniGraph xmlns="Microsoft.Search.Autopilot.Evolution" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> | ||
<CpgDec> | ||
<IsisRouters xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/> | ||
<PeeringSessions> | ||
<BGPSession> | ||
<StartRouter>OCPSCH0104001MS</StartRouter> | ||
<StartPeer>10.10.1.14</StartPeer> | ||
<EndRouter>OCPSCH01040DDLF</EndRouter> | ||
<EndPeer>10.10.1.13</EndPeer> | ||
<Multihop>1</Multihop> | ||
<HoldTime>10</HoldTime> | ||
<KeepAliveTime>3</KeepAliveTime> | ||
</BGPSession> | ||
<BGPSession> | ||
<StartRouter>OCPSCH0104002MS</StartRouter> | ||
<StartPeer>10.10.2.14</StartPeer> | ||
<EndRouter>OCPSCH01040DDLF</EndRouter> | ||
<EndPeer>10.10.2.13</EndPeer> | ||
<Multihop>1</Multihop> | ||
<HoldTime>10</HoldTime> | ||
<KeepAliveTime>3</KeepAliveTime> | ||
</BGPSession> | ||
</PeeringSessions> | ||
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"> | ||
<a:BGPRouterDeclaration> | ||
<a:ASN>64536</a:ASN> | ||
<a:Hostname>OCPSCH01040DDLF</a:Hostname> | ||
<a:Peers> | ||
<BGPPeer> | ||
<Address>10.10.1.14</Address> | ||
<RouteMapIn i:nil="true"/> | ||
<RouteMapOut i:nil="true"/> | ||
</BGPPeer> | ||
<BGPPeer> | ||
<Address>10.10.2.14</Address> | ||
<RouteMapIn i:nil="true"/> | ||
<RouteMapOut i:nil="true"/> | ||
</BGPPeer> | ||
</a:Peers> | ||
<a:RouteMaps/> | ||
</a:BGPRouterDeclaration> | ||
<a:BGPRouterDeclaration> | ||
<a:ASN>64542</a:ASN> | ||
<a:Hostname>OCPSCH0104001MS</a:Hostname> | ||
<a:RouteMaps/> | ||
</a:BGPRouterDeclaration> | ||
<a:BGPRouterDeclaration> | ||
<a:ASN>64543</a:ASN> | ||
<a:Hostname>OCPSCH0104002MS</a:Hostname> | ||
<a:RouteMaps/> | ||
</a:BGPRouterDeclaration> | ||
</Routers> | ||
</CpgDec> | ||
<DpgDec> | ||
<DeviceDataPlaneInfo> | ||
<IPSecTunnels/> | ||
<LoopbackIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"> | ||
<a:LoopbackIPInterface> | ||
<Name>HostIP</Name> | ||
<AttachTo>Loopback0</AttachTo> | ||
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.NetMux"> | ||
<b:IPPrefix>100.0.0.6/32</b:IPPrefix> | ||
</a:Prefix> | ||
<a:PrefixStr>100.0.0.6/32</a:PrefixStr> | ||
</a:LoopbackIPInterface> | ||
</LoopbackIPInterfaces> | ||
<ManagementIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"> | ||
<a:ManagementIPInterface> | ||
<Name>ManagementIP1</Name> | ||
<AttachTo>Management0</AttachTo> | ||
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.NetMux"> | ||
<b:IPPrefix>192.168.200.15/24</b:IPPrefix> | ||
</a:Prefix> | ||
<a:PrefixStr>192.168.200.15/24</a:PrefixStr> | ||
</a:ManagementIPInterface> | ||
</ManagementIPInterfaces> | ||
<MplsInterfaces/> | ||
<MplsTeInterfaces/> | ||
<RsvpInterfaces/> | ||
<Hostname>OCPSCH01040DDLF</Hostname> | ||
<PortChannelInterfaces/> | ||
<VlanInterfaces/> | ||
<IPInterfaces> | ||
<IPInterface> | ||
<Name i:nil="true"/> | ||
<AttachTo>Ethernet0</AttachTo> | ||
<Prefix>10.10.1.13/30</Prefix> | ||
</IPInterface> | ||
<IPInterface> | ||
<Name i:nil="true"/> | ||
<AttachTo>Ethernet1</AttachTo> | ||
<Prefix>10.10.2.13/30</Prefix> | ||
</IPInterface> | ||
</IPInterfaces> | ||
<DataAcls/> | ||
<AclInterfaces/> | ||
<DownstreamSummaries/> | ||
<DownstreamSummarySet xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/> | ||
</DeviceDataPlaneInfo> | ||
</DpgDec> | ||
<PngDec> | ||
<DeviceInterfaceLinks> | ||
<DeviceLinkBase i:type="DeviceInterfaceLink"> | ||
<Bandwidth>40000</Bandwidth> | ||
<ElementType>DeviceInterfaceLink</ElementType> | ||
<EndDevice>OCPSCH01040DDLF</EndDevice> | ||
<EndPort>Ethernet0</EndPort> | ||
<StartDevice>OCPSCH0104012MS</StartDevice> | ||
<StartPort>Ethernet12</StartPort> | ||
</DeviceLinkBase> | ||
<DeviceLinkBase i:type="DeviceInterfaceLink"> | ||
<Bandwidth>40000</Bandwidth> | ||
<ElementType>DeviceInterfaceLink</ElementType> | ||
<EndDevice>OCPCH01040DDLF</EndDevice> | ||
<EndPort>Ethernet1</EndPort> | ||
<StartDevice>OCPSCH0104002MS</StartDevice> | ||
<StartPort>Ethernet12</StartPort> | ||
</DeviceLinkBase> | ||
</DeviceInterfaceLinks> | ||
<Devices> | ||
<Device i:type="LeafRouter"> | ||
<Hostname>OCPSCH01040DDLF</Hostname> | ||
<HwSku>Force10-Z9100</HwSku> | ||
</Device> | ||
</Devices> | ||
</PngDec> | ||
<Hostname>OCPSCH01040DDLF</Hostname> | ||
<HwSku>Force10-Z9100</HwSku> | ||
</DeviceMiniGraph> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% for item in yml_item -%} | ||
{{ item }} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
yml_item: | ||
- value1 | ||
- value2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from unittest import TestCase | ||
import subprocess | ||
import os | ||
|
||
class TestCfgGen(TestCase): | ||
|
||
def setUp(self): | ||
self.test_dir = os.path.dirname(os.path.realpath(__file__)) | ||
self.script_file = os.path.join(self.test_dir, '..', 'sonic-cfggen') | ||
self.sample_graph = os.path.join(self.test_dir, 'sample_graph.xml') | ||
|
||
def run_script(self, argument): | ||
print '\n Running sonic-cfggen ' + argument | ||
output = subprocess.check_output(self.script_file + ' ' + argument, shell=True) | ||
linecount = output.strip().count('\n') | ||
if linecount <= 0: | ||
print ' Output: ' + output.strip() | ||
else: | ||
print ' Output: ({0} lines, {1} bytes)'.format(linecount + 1, len(output)) | ||
return output | ||
|
||
def test_dummy_run(self): | ||
argument = '' | ||
output = self.run_script(argument) | ||
self.assertEqual(output, '') | ||
|
||
def test_minigraph_sku(self): | ||
argument = '-v minigraph_hwsku -m "' + self.sample_graph + '"' | ||
output = self.run_script(argument) | ||
self.assertEqual(output.strip(), 'Force10-Z9100') | ||
|
||
def test_print_data(self): | ||
argument = '-m "' + self.sample_graph + '" --print-data' | ||
output = self.run_script(argument) | ||
self.assertTrue(len(output.strip()) > 0) | ||
|
||
def test_jinja_expression(self): | ||
argument = '-m "' + self.sample_graph + '" -v "minigraph_devices[minigraph_hostname][\'type\']"' | ||
output = self.run_script(argument) | ||
self.assertEqual(output.strip(), 'LeafRouter') | ||
|
||
def test_print_alias_mapping(self): | ||
argument = '-s' | ||
output = self.run_script(argument) | ||
self.assertTrue(len(output.strip()) > 0) | ||
|
||
def test_additional_json_data(self): | ||
argument = '-a \'{"key1":"value1"}\' -v key1' | ||
output = self.run_script(argument) | ||
self.assertEqual(output.strip(), 'value1') | ||
|
||
def test_read_yaml(self): | ||
argument = '-v yml_item -y ' + os.path.join(self.test_dir, 'test.yml') | ||
output = self.run_script(argument) | ||
self.assertEqual(output.strip(), '[\'value1\', \'value2\']') | ||
|
||
def test_render_template(self): | ||
argument = '-y ' + os.path.join(self.test_dir, 'test.yml') + ' -t' + os.path.join(self.test_dir, 'test.j2') | ||
output = self.run_script(argument) | ||
self.assertEqual(output.strip(), 'value1\nvalue2') | ||
|