class Test_get_real_servers: def setup(self): self.lm_info = { "endpoint": "https://*****:*****@1.1.1.1:443/access", "ip_address": "1.1.1.1", } self.vs = VirtualService(self.lm_info, "1.1.1.2") def test_data_exists(self): with patch.object(VirtualService, 'build_real_server') as build_real_server: with patch.object(objects, 'get_data') as get_data: with patch.object(VirtualService, '_get'): build_real_server.side_effect = sorted get_data.return_value = {'Rs': ['ba', 'ed']} res = self.vs.get_real_servers() expected = [['a', 'b'], ['d', 'e']] assert_equal(res, expected) def test_no_data_exists(self): with patch.object(VirtualService, 'build_real_server') as build_real_server: with patch.object(objects, 'get_data') as get_data: with patch.object(VirtualService, '_get'): build_real_server.side_effect = sorted get_data.return_value = {} res = self.vs.get_real_servers() expected = [] assert_equal(res, expected)
def test_init_with_no_ipaddress(self): lm_info_with_no_ip_address = { "endpoint": "https://*****:*****@1.1.1.1:443/access" } VirtualService(self.lm_info, "1.1.1.2") with assert_raises(exceptions.VirtualServiceMissingLoadmasterInfo): VirtualService(lm_info_with_no_ip_address, "1.1.1.2")
def setup(self): self.lm_info = { "endpoint": "https://1.1.1.1:443/access", "ip_address": "1.1.1.1", "auth": ("bal", "2fourall"), } self.vs = VirtualService(self.lm_info, "1.1.1.2")
class Test_build_real_server: def setup(self): self.lm_info = { "endpoint": "https://1.1.1.1:443/access", "ip_address": "1.1.1.1", "auth": ("bal", "2fourall"), } self.vs = VirtualService(self.lm_info, "1.1.1.2") def test_no_Addr(self): server = {"Port": 80} with assert_raises(ValidationError) as err: self.vs.build_real_server(server) assert_in('Addr', str(err.exception)) def test_no_Port(self): server = {"Addr": '1.1.1.1'} with assert_raises(ValidationError) as err: self.vs.build_real_server(server) assert_in('Port', str(err.exception)) def test_ok(self): server = {"Addr": '1.1.1.1', "Port": 80} res = self.vs.build_real_server(server) assert_is_instance(res, RealServer)
def setup(self): lm_info = { "endpoint": "https://*****:*****@1.1.1.1:443/access", "ip_address": "1.1.1.1", } self.vs = VirtualService(lm_info, "1.1.1.2") self.vs_info = { 'vs': self.vs, "endpoint": "https://*****:*****@1.1.1.1:443/access", "ip_address": "1.1.1.1", } self.rs = RealServer(self.vs_info, "1.1.1.2")
def setup(self): self.lm_info = { "endpoint": "https://*****:*****@1.1.1.1:443/access", "ip_address": "1.1.1.1", } self.vs = VirtualService(self.lm_info, "1.1.1.2") # Contains no subvs's self.vs_get_response = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> </Data> </Success> </Response>" # Contains default cert self.vs_get_response_defaultcert = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> <SSLAcceleration>Y</SSLAcceleration> <CertFile>f5d7b5869a48de4e30930785dcff3657</CertFile> </Data> </Success> </Response>" # Contains one cert self.vs_get_response_singlecert = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> <SSLAcceleration>Y</SSLAcceleration> <CertFile>cert1</CertFile> </Data> </Success> </Response>" # Contains multiple certs self.vs_get_response_multicert = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> <SSLAcceleration>Y</SSLAcceleration> <CertFile>cert1 cert2 cert3 cert4</CertFile> </Data> </Success> </Response>" # real server 'get' self.rs_get_response = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Rs> <Status>Down</Status> <VSIndex>0</VSIndex> <RsIndex>1</RsIndex> <Addr>10.154.123.13</Addr> <Port>80</Port> <Forward>nat</Forward> <Weight>1000</Weight> <Limit>0</Limit> <Enable>Y</Enable> <Critical>N</Critical> </Rs> </Data> </Success> </Response>" # A 'get' of a subvs self.subvs_get_response = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>2</Index> <VSPort>0</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditnone</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>1</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> </Data> </Success> </Response>" # A parent vs with a subvs newly created self.create_subvs_get_response = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>1</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <RsMinimum>0</RsMinimum> <NumberOfRSs>1</NumberOfRSs> <SubVS> <Status>Down</Status> <VSIndex>2</VSIndex> <RsIndex>1</RsIndex> <Name>-</Name> <Forward>nat</Forward> <Weight>1000</Weight> <Limit>0</Limit> <Enable>Y</Enable> <Critical>N</Critical> </SubVS> </Data> </Success> </Response>"
class Test_get_real_server: def setup(self): self.lm_info = { "endpoint": "https://1.1.1.1:443/access", "ip_address": "1.1.1.1", "auth": ("bal", "2fourall"), } self.vs = VirtualService(self.lm_info, "1.1.1.2") def test_with_index_ok(self): with patch.object(VirtualService, 'build_real_server') as build_real_server: with patch.object(objects, 'get_data'): with patch.object(VirtualService, '_get'): self.vs.index = self build_real_server.return_value = sentinel.rs res = self.vs.get_real_server('1.1.1.1', 80) assert_equal(res, sentinel.rs) def test_with_index_invalid_port(self): with patch.object(VirtualService, 'build_real_server') as build_real_server: with patch.object(objects, 'get_data'): with patch.object(VirtualService, '_get'): self.vs.index = self build_real_server.return_value = sentinel.rs with assert_raises(ValidationError): self.vs.get_real_server('1.1.1.1', 'junk') def test_without_index_ok(self): with patch.object(VirtualService, 'build_real_server') as build_real_server: with patch.object(objects, 'get_data'): with patch.object(VirtualService, '_get'): self.vs.index = None build_real_server.return_value = sentinel.rs res = self.vs.get_real_server('1.1.1.1', 80) assert_equal(res, sentinel.rs) def test_without_index_invalid_port(self): with patch.object(VirtualService, 'build_real_server') as build_real_server: with patch.object(objects, 'get_data'): with patch.object(VirtualService, '_get'): self.vs.index = None build_real_server.return_value = sentinel.rs with assert_raises(ValidationError): self.vs.get_real_server('1.1.1.1.', 'junk')
def test_init_with_no_endpoint(self): lm_info_with_no_endpoint = {"ip_address": "1.1.1.1"} VirtualService(self.lm_info, "1.1.1.2") with assert_raises(exceptions.VirtualServiceMissingLoadmasterInfo): VirtualService(lm_info_with_no_endpoint, "1.1.1.2")
def setup(self): self.lm_info = { "endpoint": "https://*****:*****@1.1.1.1:443/access", "ip_address": "1.1.1.1", } self.vs = VirtualService(self.lm_info, "1.1.1.2")
class Test_VirtualService: def setup(self): self.lm_info = { "endpoint": "https://*****:*****@1.1.1.1:443/access", "ip_address": "1.1.1.1", } self.vs = VirtualService(self.lm_info, "1.1.1.2") # Contains no subvs's self.vs_get_response = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> </Data> </Success> </Response>" # Contains default cert self.vs_get_response_defaultcert = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> <SSLAcceleration>Y</SSLAcceleration> <CertFile>f5d7b5869a48de4e30930785dcff3657</CertFile> </Data> </Success> </Response>" # Contains one cert self.vs_get_response_singlecert = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> <SSLAcceleration>Y</SSLAcceleration> <CertFile>cert1</CertFile> </Data> </Success> </Response>" # Contains multiple certs self.vs_get_response_multicert = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> <SSLAcceleration>Y</SSLAcceleration> <CertFile>cert1 cert2 cert3 cert4</CertFile> </Data> </Success> </Response>" # real server 'get' self.rs_get_response = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Rs> <Status>Down</Status> <VSIndex>0</VSIndex> <RsIndex>1</RsIndex> <Addr>10.154.123.13</Addr> <Port>80</Port> <Forward>nat</Forward> <Weight>1000</Weight> <Limit>0</Limit> <Enable>Y</Enable> <Critical>N</Critical> </Rs> </Data> </Success> </Response>" # A 'get' of a subvs self.subvs_get_response = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>2</Index> <VSPort>0</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditnone</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>0</MasterVS> <MasterVSID>1</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <EnhancedHealthChecks>N</EnhancedHealthChecks> <RsMinimum>0</RsMinimum> <NumberOfRSs>0</NumberOfRSs> </Data> </Success> </Response>" # A parent vs with a subvs newly created self.create_subvs_get_response = "<Response stat=\"200\" code=\"ok\"> <Success> <Data> <Status>Down</Status> <Index>1</Index> <VSAddress>10.154.75.123</VSAddress> <VSPort>80</VSPort> <Enable>Y</Enable> <SSLReverse>N</SSLReverse> <SSLReencrypt>N</SSLReencrypt> <Intercept>N</Intercept> <InterceptOpts> <Opt>opnormal</Opt> <Opt>auditrelevant</Opt> <Opt>reqdatadisable</Opt> <Opt>resdatadisable</Opt> </InterceptOpts> <AlertThreshold>0</AlertThreshold> <Transactionlimit>0</Transactionlimit> <Transparent>Y</Transparent> <SubnetOriginating>N</SubnetOriginating> <ServerInit>0</ServerInit> <StartTLSMode>0</StartTLSMode> <Idletime>0</Idletime> <Cache>N</Cache> <Compress>N</Compress> <Verify>0</Verify> <UseforSnat>N</UseforSnat> <ForceL7>Y</ForceL7> <MultiConnect>N</MultiConnect> <ClientCert>0</ClientCert> <ErrorCode>0</ErrorCode> <CheckUse1.1>N</CheckUse1.1> <MatchLen>0</MatchLen> <CheckUseGet>0</CheckUseGet> <SSLRewrite>0</SSLRewrite> <VStype>http</VStype> <FollowVSID>0</FollowVSID> <Protocol>tcp</Protocol> <Schedule>rr</Schedule> <CheckType>http</CheckType> <PersistTimeout>0</PersistTimeout> <CheckPort>0</CheckPort> <NRules>0</NRules> <NRequestRules>0</NRequestRules> <NResponseRules>0</NResponseRules> <NPreProcessRules>0</NPreProcessRules> <EspEnabled>N</EspEnabled> <InputAuthMode>0</InputAuthMode> <OutputAuthMode>0</OutputAuthMode> <MasterVS>1</MasterVS> <MasterVSID>0</MasterVSID> <AddVia>0</AddVia> <QoS>0</QoS> <TlsType>0</TlsType> <NeedHostName>N</NeedHostName> <OCSPVerify>N</OCSPVerify> <RsMinimum>0</RsMinimum> <NumberOfRSs>1</NumberOfRSs> <SubVS> <Status>Down</Status> <VSIndex>2</VSIndex> <RsIndex>1</RsIndex> <Name>-</Name> <Forward>nat</Forward> <Weight>1000</Weight> <Limit>0</Limit> <Enable>Y</Enable> <Critical>N</Critical> </SubVS> </Data> </Success> </Response>" def test_init_with_no_endpoint(self): lm_info_with_no_endpoint = {"ip_address": "1.1.1.1"} VirtualService(self.lm_info, "1.1.1.2") with assert_raises(exceptions.VirtualServiceMissingLoadmasterInfo): VirtualService(lm_info_with_no_endpoint, "1.1.1.2") def test_init_with_no_ipaddress(self): lm_info_with_no_ip_address = { "endpoint": "https://*****:*****@1.1.1.1:443/access" } VirtualService(self.lm_info, "1.1.1.2") with assert_raises(exceptions.VirtualServiceMissingLoadmasterInfo): VirtualService(lm_info_with_no_ip_address, "1.1.1.2") def test_str(self): assert_equal(str(self.vs), "Virtual Service TCP 1.1.1.2:80 on " "LoadMaster 1.1.1.1") def test_get_base_parameters(self): base_params = self.vs._get_base_parameters() expected_params = { "vs": "1.1.1.2", "port": 80, "prot": "tcp", } assert_equal(base_params, expected_params) self.vs.index = 1 base_params = self.vs._get_base_parameters() expected_params = { "vs": 1, } assert_equal(base_params, expected_params) def test_to_api_dict(self): actual = self.vs.to_api_dict() expected = { "vs": "1.1.1.2", "port": 80, "prot": "tcp", } assert_equal(actual, expected) def test_to_dict(self): self.vs._ignore = None actual = self.vs.to_dict() expected = { "endpoint": "https://*****:*****@1.1.1.1:443/access", "ip_address": "1.1.1.1", "vs": "1.1.1.2", "port": 80, "prot": "tcp", "subvs_entries": [], "real_servers": [], } assert_equal(actual, expected) def test_create_sub_virtual_service(self): sub_vs = self.vs.create_sub_virtual_service() actual = sub_vs._is_sub_vs expected = True assert_equal(actual, expected) def test_subvs_cant_create_sub_virtual_service(self): sub_vs = self.vs.create_sub_virtual_service() with assert_raises(exceptions.SubVsCannotCreateSubVs): sub_vs.create_sub_virtual_service() def test_vs_save_certfile_list(self): with patch.object(VirtualService, "_get") as _get: _get.return_value = self.vs_get_response_multicert self.vs.sslacceleration = "Y" self.vs.certfile = ["cert1", "cert2", "cert3", "cert4"] # use update=True to skip some code not in test for this case self.vs.save(update=True) expected = ["cert1", "cert2", "cert3", "cert4"] actual = self.vs.certfile assert_equal(actual, expected) def test_vs_save_certfile_str(self): with patch.object(VirtualService, "_get") as _get: _get.return_value = self.vs_get_response_singlecert print(self.vs.__repr__()) self.vs.sslacceleration = "Y" self.vs.certfile = "cert1" # use update=True to skip some code not in test for this case self.vs.save(update=True) print(self.vs.__repr__()) expected = ["cert1"] actual = self.vs.certfile assert_equal(actual, expected) def test_vs_save_certfile_None(self): with patch.object(VirtualService, "_get") as _get: _get.return_value = self.vs_get_response_defaultcert self.vs.sslacceleration = "N" self.vs.certfile = "" # use update=True to skip some code not in test for this case self.vs.save(update=True) expected = [] actual = self.vs.certfile assert_equal(actual, expected) def test_vs_save_persist(self): with patch.object(VirtualService, "_get") as _get: _get.return_value = self.vs_get_response self.vs.persist = None # use update=True to skip some code not in test for this case self.vs.save(update=True) expected = None actual = self.vs.persisttimeout assert_equal(actual, expected) def test_save_add_normal_vs(self): with patch.object(VirtualService, "_get") as _get: _get.return_value = self.vs_get_response expected = None actual = self.vs.index assert_equal(actual, expected) self.vs.save() expected = "1" actual = self.vs.index assert_equal(actual, expected) def test_save_add_sub_vs(self): with patch.object(VirtualService, "_get") as _get: # set the index to pretend the parent vs has already been "saved" self.vs.index = 1 subvs = self.vs.create_sub_virtual_service() _get.side_effect = [ self.vs_get_response, self.create_subvs_get_response, self.subvs_get_response ] # This will run through the big "Hell, thy name be subvs" block in VirtualService's save method subvs.save() expected = "2" actual = subvs.index assert_equal(actual, expected) expected = [] actual = subvs.subvs_data assert_not_equal(actual, expected) def test_save_update_sub_vs(self): with patch.object(VirtualService, "_get") as _get: with patch.object(VirtualService, "_subvs_to_dict") as _subvs_to_dict: _subvs_to_dict.return_value = { "vs": "1", "rs": "!1", "name": "asdf", "forward": "asdf", "weight": "sdf", "limit": "sdf", "critical": "sdf", "enable": "sdf", } # set the index to pretend the parent vs has already been "saved" self.vs.index = 1 subvs = self.vs.create_sub_virtual_service() _get.return_value = self.subvs_get_response subvs.save(update=True) expected = "2" actual = subvs.index assert_equal(actual, expected) expected = [] actual = subvs.subvs_data assert_not_equal(actual, expected)
def build_virtual_service(self, service, response=None): """Create a VirtualService instance with populated with API parameters This does not include potentially attached real servers :param service: OrderedDict populated with virtual service data :param response: Optional response of a listvs call. This acts as a cache, if you want to create a lot of VirtualService objects in a row, such as with looping, you can call listvs and pass the response in each time and this will nullify the extra listvs calls. :return: VirtualService object with populated attributes """ is_sub_vs = True if int(service.get('MasterVSID', 0)) != 0 else False if is_sub_vs: # `response` needs to be a dict in here # Add lb properties to the sub vs if response is None: response = self._get("/showvs", {"vs": service.get('MasterVSID')}) parent_vs_data = get_data(response) else: parent_vs_data = response subvs_lb_props = get_sub_vs_list_from_data(parent_vs_data)[1] virt_serv = VirtualService(self.access_info, service.get('Index'), is_sub_vs=True) virt_serv.subvs_data = subvs_lb_props[service.get('Index')] virt_serv.subvs_data['parentvs'] = service.get('MasterVSID') else: # `response` needs to be a raw xml output here # Add any sub VSs to the top level VS if response is None: response = self._get("/listvs") data = get_data(response) virt_serv = VirtualService(self.access_info, service.get('VSAddress'), service.get('VSPort'), service.get('Protocol'), is_sub_vs=False) virt_serv.subvs_entries = [] services = get_dict_entry_as_list("VS", data) this_vs_index = service.get('Index') for vs in services: # add subvs to parent vs if vs['MasterVSID'] == this_vs_index: subvs = VirtualService(self.access_info, vs['Index'], is_sub_vs=True) subvs.populate_default_attributes(vs) subvs_api_entries = service.get("SubVS", []) subvs_api_entries = cast_to_list(subvs_api_entries) for subvs_api in subvs_api_entries: # add the "Rs" part of the subvs to the subvs instance if subvs_api["VSIndex"] == subvs.index: subvs.subvs_data = subvs_api # Have to add a parentvs hook to make life easy subvs.subvs_data['parentvs'] = this_vs_index virt_serv.subvs_entries.append(subvs) virt_serv.populate_default_attributes(service) return virt_serv
def create_virtual_service(self, ip, port=80, protocol="tcp"): return VirtualService(self.access_info, ip, port, protocol)