vmware-archive / powernsx

PowerShell module that abstracts the VMware NSX-v API to a set of easily used PowerShell functions
173 stars 89 forks source link

'descendant' shouldn't be used to check whether or not edge/DLR has 'bgp'/'ospf' xml tree #303

Open yktsubo opened 7 years ago

yktsubo commented 7 years ago

If using 'descendant::bgp' to the following routing config, "Invoke-XPathQuery -QueryMethod SelectSingleNode -Node $xmlGlobalConfig -Query 'descendant::bgp'" returns non-NUll. Because bgp element exists under redistribution-rule.

When knowing the xml is a child of another xml, child should be used.

# Fail case
PS > $bgp = [System.Xml.XmlDocumentXPathExtensions]::SelectSingleNode($logicalrouter.features.routing,'descendant::bgp')
PS > if ($bgp ) { write-host 'true' } else { write-host 'false' }
true
# good case
PS > $bgp = [System.Xml.XmlDocumentXPathExtensions]::SelectSingleNode($logicalrouter.features.routing,'child::bgp')
PS > if ($bgp ) { write-host 'true' } else { write-host 'false' }
false

# Example of logicalrouter config
<snip>
      <routing>
       <ospf>
<snip>
          <redistribution>
            <enabled>true</enabled>
            <rules>
              <rule>
                <id>0</id>
                <from>
                  <ospf>false</ospf>
                  <bgp>false</bgp>
                  <static>false</static>
                  <connected>true</connected>
                </from>
                <action>permit</action>
              </rule>
              <rule>
                <id>1</id>
                <from>
                  <ospf>false</ospf>
                  <bgp>false</bgp>
                  <static>true</static>
                  <connected>false</connected>
                </from>
                <action>permit</action>
              </rule>
            </rules>
          </redistribution>
        </ospf>
      </routing>
nmbradford commented 7 years ago

Hi Yuki - looks like @Virtualizestuff has hit something related. Are you in a position to do a scrub on the bgp / ospf cmdets and see how wide spread this is, define tests that expose it and potentially work on a fix?

yktsubo commented 7 years ago

Hi Nick, Ok I'll check them.