def get_single_virtual_switch(self): virtual_switch_list = [] virtual_switch = VirtualSwitch() virtual_switch.set_id('virtual-switch-01') virtual_switch.set_name('virtual-switch-01') virtual_switch.set_switchType('dvSwitch') virtual_switch.add_subnetIds('subnet-3883') virtual_switch.add_subnetIds('subnet-323') virtual_switch_list.append(virtual_switch) return virtual_switch_list
def get_single_virtual_switch(self): virtual_switch_list = [] virtual_switch = VirtualSwitch() virtual_switch.set_id("virtual-switch-01") virtual_switch.set_name("virtual-switch-01") virtual_switch.set_switchType("dvSwitch") virtual_switch.add_subnetIds("subnet-3883") virtual_switch.add_subnetIds("subnet-323") virtual_switch_list.append(virtual_switch) return virtual_switch_list
def test_subnet_delete(self): subnet = Subnet() subnet.set_id('subnet-01') subnet.set_name('subnet-01') subnet.set_networkAddress('1.1.1.1') subnet.set_networkMask('255.255.255.0') subnet.add_networkSources('VS_NETWORK') subnet.set_ipType('IPV4') subnet.set_isPublic(True) subnet.set_isShareable(True) subnet.add_dnsServers('test-dns01') subnet.set_dnsDomain('test_Domain') subnet.add_dnsSearchSuffixes('dnsSearchSuffixes') subnet.add_defaultGateways('defaultGateways') subnet.set_msDomainName('msDomainName') subnet.set_msDomainType('WORKGROUP') subnet.add_winsServers('winsServers') subnet.add_ntpDateServers('ntpDateServers') subnet.set_vlanId(1) subnet.set_isBootNetwork(True) subnet.add_deploymentServices('deploymentServices') subnet.add_parentIds('parentIds') subnet.add_childIds('childIds') subnet.set_isTrunk(True) subnet.add_redundancyPeerIds('redundancyPeerIds') subnet.set_redundancyMasterId('redundancyMasterId') subnet.set_isNativeVlan(False) userIp = IpAddress() userIp.set_id('10.10.20.1') userIp.set_address('10.10.20.1') subnet.add_usedIpAddresses(userIp) ipRange = self._create_ip_range_from_xml(subnet.get_id( ), 'network1', '10.10.10.1', '10.10.10.1', '10.10.10.2') subnet.add_ipAddressRanges(ipRange) healthnmon_db_api.subnet_save(self.admin_context, subnet) subnet2 = Subnet() subnet2.set_id('subnet-02') subnet2.set_name('subnet-02') healthnmon_db_api.subnet_save(self.admin_context, subnet2) vSwitch = VirtualSwitch() vSwitch.set_id('vs-01') vSwitch.set_name('vs-01') vSwitch.add_subnetIds('subnet-01') vSwitch.add_subnetIds('subnet-02') healthnmon_db_api.virtual_switch_save(self.admin_context, vSwitch) healthnmon_db_api.subnet_delete_by_ids(self.admin_context, [subnet.id]) subnets = healthnmon_db_api.subnet_get_by_ids(self.admin_context, [subnet.id]) self.assertTrue(subnets is None or len(subnets) == 0, 'subnet deleted')
def get_virtual_switch_list(self): virtual_switch_list = [] virtual_switch = VirtualSwitch() virtual_switch.set_id('virtual-switch-01') virtual_switch.set_name('virtual-switch-01') virtual_switch.set_switchType('type-01') virtual_switch.add_subnetIds('subnet-233') virtual_switch.add_subnetIds('subnet-03') virtual_switch_list.append(virtual_switch) virtual_switch = VirtualSwitch() virtual_switch.set_id('virtual-switch-02') virtual_switch.set_name('virtual-switch-02') virtual_switch.set_switchType('type-02') virtual_switch.add_subnetIds('subnet-392') virtual_switch_list.append(virtual_switch) return virtual_switch_list
def get_virtual_switch_list(self): virtual_switch_list = [] virtual_switch = VirtualSwitch() virtual_switch.set_id("virtual-switch-01") virtual_switch.set_name("virtual-switch-01") virtual_switch.set_switchType("type-01") virtual_switch.add_subnetIds("subnet-233") virtual_switch.add_subnetIds("subnet-03") virtual_switch_list.append(virtual_switch) virtual_switch = VirtualSwitch() virtual_switch.set_id("virtual-switch-02") virtual_switch.set_name("virtual-switch-02") virtual_switch.set_switchType("type-02") virtual_switch.add_subnetIds("subnet-392") virtual_switch_list.append(virtual_switch) return virtual_switch_list
def test_virtual_switch_save_with_subnet(self): # Save virtual switch with a port group vSwitch = VirtualSwitch() vSwitch.set_id("vSwitch-11") vSwitch.set_name("vSwitch-11") vSwitch.set_resourceManagerId("rmId") vSwitch.set_switchType("vSwitch") cost1 = Cost() cost1.set_value(100) cost1.set_units("USD") vSwitch.set_cost(cost1) portGroup = PortGroup() portGroup.set_id("pg-01") portGroup.set_name("pg-01") portGroup.set_resourceManagerId("rmId") portGroup.set_type("portgroup_type") portGroup.set_cost(cost1) vSwitch.add_portGroups(portGroup) api.virtual_switch_save(self.admin_context, vSwitch) # Update after adding a port group and subnet vSwitch = api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id])[0] portGroup2 = PortGroup() portGroup2.set_id("pg-02") portGroup2.set_name("pg-02") portGroup2.set_resourceManagerId("rmId") portGroup2.set_type("portgroup_type") vSwitch.add_portGroups(portGroup2) subnet = Subnet() subnet.set_id("subnet-02") subnet.set_name("subnet-02") subnet.set_networkAddress("1.1.1.1") api.subnet_save(self.admin_context, subnet) vSwitch.add_subnetIds(subnet.id) vSwitch.add_networkInterfaces("1") api.virtual_switch_save(self.admin_context, vSwitch) virtualswitches = api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id]) # Assert the values self.assertTrue(len(virtualswitches) == 1, "Unexpected number of Virtual Switch returned") self.assertTrue(virtualswitches[0].get_id() == "vSwitch-11", "Virtual Switch id mismatch") self.assertTrue(virtualswitches[0].get_name() == "vSwitch-11", "Virtual Switch name mismatch") self.assertTrue( virtualswitches[0].get_resourceManagerId() == "rmId", "Virtual Switch Resource Manager id mismatch" ) self.assertTrue(virtualswitches[0].get_switchType() == "vSwitch", "Virtual Switch type mismatch") cost1 = virtualswitches[0].get_cost() self.assertTrue(cost1.get_value() == 100, "VSwitch Cost Value mismatch") self.assertTrue(cost1.get_units() == "USD", "VSwitch Cost units mismatch") portGroups = virtualswitches[0].get_portGroups() self.assertTrue(len(portGroups) == 2, "All the portgroups have not been saved") self.assertTrue(portGroups[0].get_id() == "pg-01", "VSwitch Port Group id mismatch") self.assertTrue(portGroups[0].get_name() == "pg-01", "VSwitch Port Group Name mismatch") self.assertTrue( portGroups[0].get_resourceManagerId() == "rmId", "VSwitch portgroup Resource Manager id mismatch" ) self.assertTrue(portGroups[0].get_type() == "portgroup_type", "VSwitch port group type mismatched") cost2 = portGroups[0].get_cost() self.assertTrue(cost2.get_value() == 100, "PortGroup Cost Value mismatch") self.assertTrue(cost2.get_units() == "USD", "PortGroup Cost units mismatch") self.assertTrue(portGroups[1].get_id() == "pg-02", "VSwitch Port Group id mismatch") self.assertTrue(portGroups[1].get_name() == "pg-02", "VSwitch Port Group Name mismatch") self.assertTrue( portGroups[1].get_resourceManagerId() == "rmId", "VSwitch portgroup Resource Manager id mismatch" ) self.assertTrue(portGroups[1].get_type() == "portgroup_type", "VSwitch port group type mismatched") subnetId = virtualswitches[0].get_subnetIds() self.assertTrue(subnetId[0] == "subnet-02", "Virtual Switch subnet id mismatch") self.assertTrue( virtualswitches[0].get_networkInterfaces()[0] == "1", "Virtual Switch network INterfaces mismatch" )
def test_virtual_switch_save_with_subnet(self): # Save virtual switch with a port group vSwitch = VirtualSwitch() vSwitch.set_id('vSwitch-11') vSwitch.set_name('vSwitch-11') vSwitch.set_resourceManagerId('rmId') vSwitch.set_switchType('vSwitch') cost1 = Cost() cost1.set_value(100) cost1.set_units('USD') vSwitch.set_cost(cost1) portGroup = PortGroup() portGroup.set_id('pg-01') portGroup.set_name('pg-01') portGroup.set_resourceManagerId('rmId') portGroup.set_type('portgroup_type') portGroup.set_cost(cost1) vSwitch.add_portGroups(portGroup) api.virtual_switch_save(self.admin_context, vSwitch) # Update after adding a port group and subnet vSwitch = api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id])[0] portGroup2 = PortGroup() portGroup2.set_id('pg-02') portGroup2.set_name('pg-02') portGroup2.set_resourceManagerId('rmId') portGroup2.set_type('portgroup_type') vSwitch.add_portGroups(portGroup2) subnet = Subnet() subnet.set_id('subnet-02') subnet.set_name('subnet-02') subnet.set_networkAddress('1.1.1.1') api.subnet_save(self.admin_context, subnet) vSwitch.add_subnetIds(subnet.id) vSwitch.add_networkInterfaces('1') api.virtual_switch_save(self.admin_context, vSwitch) virtualswitches = \ api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id]) # Assert the values self.assertTrue(len(virtualswitches) == 1, 'Unexpected number of Virtual Switch returned') self.assertTrue(virtualswitches[0].get_id( ) == 'vSwitch-11', 'Virtual Switch id mismatch') self.assertTrue(virtualswitches[0].get_name( ) == 'vSwitch-11', 'Virtual Switch name mismatch') self.assertTrue(virtualswitches[0].get_resourceManagerId( ) == 'rmId', 'Virtual Switch Resource Manager id mismatch') self.assertTrue(virtualswitches[0].get_switchType( ) == 'vSwitch', 'Virtual Switch type mismatch') cost1 = virtualswitches[0].get_cost() self.assertTrue( cost1.get_value() == 100, 'VSwitch Cost Value mismatch') self.assertTrue( cost1.get_units() == 'USD', 'VSwitch Cost units mismatch') portGroups = virtualswitches[0].get_portGroups() self.assertTrue( len(portGroups) == 2, 'All the portgroups have not been saved') self.assertTrue(portGroups[0].get_id( ) == 'pg-01', 'VSwitch Port Group id mismatch') self.assertTrue(portGroups[0].get_name( ) == 'pg-01', 'VSwitch Port Group Name mismatch') self.assertTrue(portGroups[0].get_resourceManagerId( ) == 'rmId', 'VSwitch portgroup Resource Manager id mismatch') self.assertTrue(portGroups[0].get_type( ) == 'portgroup_type', 'VSwitch port group type mismatched') cost2 = portGroups[0].get_cost() self.assertTrue( cost2.get_value() == 100, 'PortGroup Cost Value mismatch') self.assertTrue( cost2.get_units() == 'USD', 'PortGroup Cost units mismatch') self.assertTrue(portGroups[1].get_id( ) == 'pg-02', 'VSwitch Port Group id mismatch') self.assertTrue(portGroups[1].get_name( ) == 'pg-02', 'VSwitch Port Group Name mismatch') self.assertTrue(portGroups[1].get_resourceManagerId( ) == 'rmId', 'VSwitch portgroup Resource Manager id mismatch') self.assertTrue(portGroups[1].get_type( ) == 'portgroup_type', 'VSwitch port group type mismatched') subnetId = virtualswitches[0].get_subnetIds() self.assertTrue( subnetId[0] == 'subnet-02', 'Virtual Switch subnet id mismatch') self.assertTrue(virtualswitches[0].get_networkInterfaces( )[0] == '1', 'Virtual Switch network INterfaces mismatch')
def test_virtual_switch_save_with_subnet(self): # Save virtual switch with a port group vSwitch = VirtualSwitch() vSwitch.set_id('vSwitch-11') vSwitch.set_name('vSwitch-11') vSwitch.set_resourceManagerId('rmId') vSwitch.set_switchType('vSwitch') cost1 = Cost() cost1.set_value(100) cost1.set_units('USD') vSwitch.set_cost(cost1) portGroup = PortGroup() portGroup.set_id('pg-01') portGroup.set_name('pg-01') portGroup.set_resourceManagerId('rmId') portGroup.set_type('portgroup_type') portGroup.set_cost(cost1) vSwitch.add_portGroups(portGroup) api.virtual_switch_save(self.admin_context, vSwitch) # Update after adding a port group and subnet vSwitch = api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id])[0] portGroup2 = PortGroup() portGroup2.set_id('pg-02') portGroup2.set_name('pg-02') portGroup2.set_resourceManagerId('rmId') portGroup2.set_type('portgroup_type') vSwitch.add_portGroups(portGroup2) subnet = Subnet() subnet.set_id('subnet-02') subnet.set_name('subnet-02') subnet.set_networkAddress('1.1.1.1') api.subnet_save(self.admin_context, subnet) vSwitch.add_subnetIds(subnet.id) vSwitch.add_networkInterfaces('1') api.virtual_switch_save(self.admin_context, vSwitch) virtualswitches = \ api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id]) # Assert the values self.assertTrue( len(virtualswitches) == 1, 'Unexpected number of Virtual Switch returned') self.assertTrue(virtualswitches[0].get_id() == 'vSwitch-11', 'Virtual Switch id mismatch') self.assertTrue(virtualswitches[0].get_name() == 'vSwitch-11', 'Virtual Switch name mismatch') self.assertTrue(virtualswitches[0].get_resourceManagerId() == 'rmId', 'Virtual Switch Resource Manager id mismatch') self.assertTrue(virtualswitches[0].get_switchType() == 'vSwitch', 'Virtual Switch type mismatch') cost1 = virtualswitches[0].get_cost() self.assertTrue(cost1.get_value() == 100, 'VSwitch Cost Value mismatch') self.assertTrue(cost1.get_units() == 'USD', 'VSwitch Cost units mismatch') portGroups = virtualswitches[0].get_portGroups() self.assertTrue( len(portGroups) == 2, 'All the portgroups have not been saved') self.assertTrue(portGroups[0].get_id() == 'pg-01', 'VSwitch Port Group id mismatch') self.assertTrue(portGroups[0].get_name() == 'pg-01', 'VSwitch Port Group Name mismatch') self.assertTrue(portGroups[0].get_resourceManagerId() == 'rmId', 'VSwitch portgroup Resource Manager id mismatch') self.assertTrue(portGroups[0].get_type() == 'portgroup_type', 'VSwitch port group type mismatched') cost2 = portGroups[0].get_cost() self.assertTrue(cost2.get_value() == 100, 'PortGroup Cost Value mismatch') self.assertTrue(cost2.get_units() == 'USD', 'PortGroup Cost units mismatch') self.assertTrue(portGroups[1].get_id() == 'pg-02', 'VSwitch Port Group id mismatch') self.assertTrue(portGroups[1].get_name() == 'pg-02', 'VSwitch Port Group Name mismatch') self.assertTrue(portGroups[1].get_resourceManagerId() == 'rmId', 'VSwitch portgroup Resource Manager id mismatch') self.assertTrue(portGroups[1].get_type() == 'portgroup_type', 'VSwitch port group type mismatched') subnetId = virtualswitches[0].get_subnetIds() self.assertTrue(subnetId[0] == 'subnet-02', 'Virtual Switch subnet id mismatch') self.assertTrue(virtualswitches[0].get_networkInterfaces()[0] == '1', 'Virtual Switch network INterfaces mismatch')