Exemple #1
0
 def do_show_stored_network(self, arg):
     """
     show_stored_network NUM. 
     Shows information about a previously used network.
     It is needed to list_stored_networks first and use that numbers as a parameter 
     to this command.
     """
     larg = arg.split()
     if len(larg) >= 1:
         nid = larg[0]
         if hasattr(self, 'stored_networks'):
             if nid in self.stored_networks:
                 print(util.deserialize_net_from_file(self.stored_networks[nid]))
             else:
                logger.error('The network {} is not in the list of stored networks'.format(nid)) 
         else:
             logger.error('You have to list stored networks first')
Exemple #2
0
 def do_connect_stored_network(self, arg):
     """
     connect_stored_network NUM. 
     Try to connect to a wireless network that has been previously used. 
     It is necessary to list them first with list_stored_networks.
     The parameter NUM must be one of the numbers on that list.
     """
     larg = arg.split()
     if len(larg) >= 1:
         nid = larg[0]
         if hasattr(self, 'stored_networks'):
             if nid in self.stored_networks:
                 if not hasattr(self, 'c_manager'):
                     self.c_manager = c_manager.ConnectionManager(self.config)
                 net = util.deserialize_net_from_file(self.stored_networks[nid])    
                 self.c_manager.connect(net, False)
             else:
                logger.error('The network {} is not in the list of stored networks'.format(nid)) 
         else:
             logger.error('You have to list stored networks first')
Exemple #3
0
    def test_serializer(self):
        '''
        This test checks:
          * the serialization and storage of the network for later use. For each test network
          we write to a file (pickle), and then we read from that file, checking that it
          is identical to the original network
          * several other auxiliary functions related with storage and retrieval of network
          configuration files
        '''
        net_1_conf = self.cman.get_network_conf_file(self.net_1)
        net_2_conf = self.cman.get_network_conf_file(self.net_2)
        net_3_conf = self.cman.get_network_conf_file(self.net_3)
        net_4_conf = self.cman.get_network_conf_file(self.net_4)
        net_5_conf = self.cman.get_network_conf_file(self.net_5)

        self.net_1_ser = util.build_net_serialization_filename(net_1_conf)
        self.net_2_ser = util.build_net_serialization_filename(net_2_conf)
        self.net_3_ser = util.build_net_serialization_filename(net_3_conf)
        self.net_4_ser = util.build_net_serialization_filename(net_4_conf)
        self.net_5_ser = util.build_net_serialization_filename(net_5_conf)
        
        self.assertTrue(util.is_net_serialization_filename(self.net_1_ser))
        self.assertTrue(util.is_net_serialization_filename(self.net_2_ser))
        self.assertTrue(util.is_net_serialization_filename(self.net_3_ser))
        self.assertTrue(util.is_net_serialization_filename(self.net_4_ser))
        self.assertTrue(util.is_net_serialization_filename(self.net_5_ser))

        #calls to serialize_net_to_file have the side effect of creating a pickle file
        self.assertEqual(
            util.serialize_net_to_file(net_1_conf, self.net_1),
            self.net_1_ser
        )
        self.assertEqual(
            util.serialize_net_to_file(net_2_conf, self.net_2),
            self.net_2_ser
        )
        self.assertEqual(
            util.serialize_net_to_file(net_3_conf, self.net_3),
            self.net_3_ser
        )
        self.assertEqual(
            util.serialize_net_to_file(net_4_conf, self.net_4),
            self.net_4_ser
        )
        self.assertEqual(
            util.serialize_net_to_file(net_5_conf, self.net_5),
            self.net_5_ser
        )
        
        #test that we have the same networks after deserialization
        self.assertEqual(
            util.deserialize_net_from_file(net_1_conf),
            self.net_1
        )
        self.assertEqual(
            util.deserialize_net_from_file(net_2_conf),
            self.net_2
        )
        self.assertEqual(
            util.deserialize_net_from_file(net_3_conf),
            self.net_3
        )
        self.assertEqual(
            util.deserialize_net_from_file(net_4_conf),
            self.net_4
        )
        self.assertEqual(
            util.deserialize_net_from_file(net_5_conf),
            self.net_5
        )
        
        for n in [self.net_1_ser, self.net_2_ser, self.net_3_ser, self.net_4_ser,
                  self.net_5_ser]:
            try:
                remove(n)
            except OSError:
                pass