Esempio n. 1
0
    def test_pure_json_autoconnect_bool(self):
        data = """
        {
            "connection": {
                "id": "Pifi AP Mode",
                "type": "802-11-wireless",
                "autoconnect": false,
                "uuid": "foo-bar-foo-bar"
            }
        }
        """

        f = mock.mock_open(read_data=data)
        conf = etc_io.get_default_ap_conf('AF:BF:CF:0F:1F:2F', open=f)
        self.assertIsInstance(conf['connection']['autoconnect'], bool)
        self.assertEqual(conf['connection']['autoconnect'], False)
        self.assertIsInstance(conf, dict)

        data = """
        {
            "connection": {
                "id": "Pifi AP Mode",
                "type": "802-11-wireless",
                "autoconnect": true,
                "uuid": "foo-bar-foo-bar"
            }
        }
        """

        f = mock.mock_open(read_data=data)
        conf = etc_io.get_default_ap_conf('AF:BF:CF:0F:1F:2F', open=f)
        self.assertIsInstance(conf['connection']['autoconnect'], bool)
        self.assertEqual(conf['connection']['autoconnect'], True)
        self.assertIsInstance(conf, dict)
Esempio n. 2
0
def start_ap_mode(pifi_conf_settings, ApModeDevice, ClientModeDevice):
        print("Starting AP mode")

        if pifi_conf_settings['delete_existing_ap_connections'] == False:
            print("Looking for existing AP mode connection")

            for connection in nm.existingAPConnections():
                print("Found existing AP mode connection, SSID: %s" % 
                    connection.GetSettings()['802-11-wireless']['ssid'])
                print("Initializing AP Mode")
                NetworkManager.NetworkManager.ActivateConnection(connection, ApModeDevice, "/")
                return # We don't acutally want to loop, just use the first iter
        else:
            for connection in nm.existingAPConnections():
                print("Deleting existing AP mode connection, SSID: %s" % 
                    connection.GetSettings()['802-11-wireless']['ssid'])
                connection.Delete()

        print("No existing AP mode connections found")
        print("Creating new default AP mode connection with config:")

        # Default AP mode connection
        settings = etc_io.get_default_ap_conf(ApModeDevice.HwAddress)
        print(json.dumps(settings, indent=1)) ## Pretty Print settings

        print("Initializing AP Mode")
        NetworkManager.NetworkManager.AddAndActivateConnection(settings, ApModeDevice, "/")

        status_led = pifi_conf_settings['status_led'] 
        leds.blink(status_led, delay_on=100, delay_off=500)
Esempio n. 3
0
 def test_nonexistant_get_default_ap_conf(self):
     f = mock.Mock(side_effect=FileNotFoundError('foo'))
     conf = etc_io.get_default_ap_conf('AF:BF:CF:0F:1F:2F', open=f)
     self.assertIsInstance(conf, dict)
     self.assertEqual(conf['802-11-wireless']['mode'], 'ap')
Esempio n. 4
0
 def test_templated_json_get_default_ap_conf(self):
     f = mock.mock_open(read_data='{"Foo" : "@(mac)"}')
     conf = etc_io.get_default_ap_conf('AF:BF:CF:0F:1F:2F', open=f)
     self.assertIsInstance(conf, dict)
     self.assertEqual(conf, {'Foo': 'AF:BF:CF:0F:1F:2F'})
Esempio n. 5
0
 def test_pure_json_get_default_ap_conf(self):
     f = mock.mock_open(read_data=json.dumps({'Foo': 'Bar'}))
     conf = etc_io.get_default_ap_conf('AF:BF:CF:0F:1F:2F', open=f)
     self.assertIsInstance(conf, dict)
     self.assertEqual(conf, {'Foo': 'Bar'})
Esempio n. 6
0
 def test_bad_template_get_default_ap_conf(self):
     f = mock.mock_open(read_data='{"Foo" : "@(foo)"}')
     conf = etc_io.get_default_ap_conf('AF:BF:CF:0F:1F:2F', open=f)
     self.assertIsInstance(conf, dict)
     self.assertEqual(conf['802-11-wireless']['mode'], 'ap')