Esempio n. 1
0
 def test_04_VirtNet(self):
     """
     Populate database with max - 1 mac addresses
     """
     try:
         os.unlink(self.db_filename)
     except OSError:
         pass
     self.zero_counter(25)
     # setup() method already set LASTBYTE to '-1'
     for lastbyte in xrange(0, 0xFF):
         # test_07_VirtNet demands last byte in name and mac match
         vm_name = "vm%d" % lastbyte
         if lastbyte < 16:
             mac = "%s0%x" % (self.mac_prefix,lastbyte)
         else:
             mac = "%s%x" % (self.mac_prefix,lastbyte)
         params = utils_misc.Params({
             "nics":"nic1",
             "vms":vm_name,
             "mac_nic1":mac,
         })
         virtnet = utils_misc.VirtNet(params, vm_name,
                                      vm_name, self.db_filename)
         virtnet.mac_prefix = self.mac_prefix
         self.assertEqual(virtnet['nic1'].mac, mac)
         self.assertEqual(virtnet.get_mac_address(0), mac)
         # Confirm only lower-case macs are stored
         self.assertEqual(virtnet.get_mac_address(0).lower(),
                          virtnet.get_mac_address(0))
         self.assertEqual(virtnet.mac_list(), [mac] )
         self.print_and_inc()
Esempio n. 2
0
 def test_07_VirtNet(self):
     """
     Release mac from beginning, midle, and end, re-generate + verify value
     """
     self.zero_counter(1)
     beginning_params = utils_misc.Params({
         "nics":"nic1 nic2",
         "vms":"vm0"
     })
     middle_params = utils_misc.Params({
         "nics":"nic1 nic2",
         "vms":"vm127"
     })
     end_params = utils_misc.Params({
         "nics":"nic1 nic2",
         "vms":"vm255",
     })
     for params in (beginning_params,middle_params,end_params):
         vm_name = params['vms']
         virtnet = utils_misc.VirtNet(params, vm_name,
                                      vm_name, self.db_filename)
         virtnet.mac_prefix = self.mac_prefix
         iface = virtnet['nic1']
         last_db_mac_byte = iface.mac_str_to_int_list(iface.mac)[-1]
         last_vm_name_byte = int(vm_name[2:])
         # Sequential generation from test_04_VirtNet guarantee
         self.assertEqual(last_db_mac_byte, last_vm_name_byte)
         # only try 300 times, guarantees LASTBYTE counter will loop once
         self.assertRaises(utils_misc.NetError,
                           virtnet.generate_mac_address, 1, 300)
         virtnet.free_mac_address(0)
         virtnet.free_mac_address(1)
         # generate new on nic1 to verify mac_index generator catches it
         # and to signify database updated after generation
         mac = virtnet.generate_mac_address(1,300)
         last_db_mac_byte = virtnet['nic2'].mac_str_to_int_list(
             virtnet['nic2'].mac)[-1]
         self.assertEqual(last_db_mac_byte, last_vm_name_byte)
         self.assertEqual(virtnet.get_mac_address(1), virtnet[1].mac)
         self.print_and_inc()
Esempio n. 3
0
 def setUp(self):
     """
     Runs before every test
     """
     # MAC generator produces from incrementing byte list
     # at random starting point (class property).
     # make sure it starts counting at zero before every test
     utils_misc.VirtIface.LASTBYTE = -1
     # These warnings are annoying during testing
     utils_misc.VMNet.DISCARD_WARNINGS -1
     parser = cartesian_config.Parser()
     parser.parse_string(self.nettests_cartesian)
     self.CartesianResult = []
     for d in parser.get_dicts():
         params = utils_misc.Params(d)
         self.CartesianResult.append(params)
         for vm_name in params.objects('vms'):
             vm = params.object_params(vm_name)
             nics = vm.get('nics')
             if nics and len(nics.split()) > 0:
                 self.db_item_count += 1
Esempio n. 4
0
    def test_06_VirtNet(self):
        """
        Generate last possibly mac and verify value.

        DEPENDS ON test_05_VirtNet running first
        """
        self.zero_counter(25)
        # test two nics, second mac generation should fail (pool exhausted)
        params = utils_misc.Params({
            "nics":"nic1 nic2",
            "vms":"vm255"
        })
        virtnet = utils_misc.VirtNet(params, 'vm255',
                                     'vm255', self.db_filename)
        virtnet.mac_prefix = self.mac_prefix
        self.assertRaises(utils_misc.PropCanKeyError,
                          virtnet.get_mac_address, 'nic1')
        mac = "%s%x" % (self.mac_prefix,255)
        # This will grab the last available address
        # only try 300 times, guarantees LASTBYTE counter will loop once
        self.assertEqual(virtnet.generate_mac_address(0, 300), mac)
        # This will fail allocation
        self.assertRaises(utils_misc.NetError,
                            virtnet.generate_mac_address, 1, 300)
Esempio n. 5
0
    def test_05_VirtNet(self):
        """
        Load max - 1 entries from db, overriding params.

        DEPENDS ON test_04_VirtNet running first
        """
        self.zero_counter(25)
        # second loop forces db load from disk
        # also confirming params merge with db data
        for lastbyte in xrange(0, 0xFF):
            vm_name = "vm%d" % lastbyte
            params = utils_misc.Params({
                "nics":"nic1",
                "vms":vm_name
            })
            virtnet = utils_misc.VirtNet(params, vm_name,
                                         vm_name, self.db_filename)
            if lastbyte < 16:
                mac = "%s0%x" % (self.mac_prefix,lastbyte)
            else:
                mac = "%s%x" % (self.mac_prefix,lastbyte)
            self.assertEqual(virtnet['nic1'].mac, mac)
            self.assertEqual(virtnet.get_mac_address(0), mac)
            self.print_and_inc()