Exemplo n.º 1
0
    def test_03_check_hypervisor_config(self):
        c = fcdbus.FleetCommanderDbusClient()

        data = {
            'host': 'localhost',
            'username': '******',
            'mode': 'session',
            'adminhost': '',
        }

        # Set invalid host data
        idata = data.copy()
        idata['host'] = 'invalid_host'
        resp = c.check_hypervisor_config(idata)
        self.assertFalse(resp['status'])
        self.assertEqual(resp['errors'],
                         {'host': 'Invalid hostname specified'})

        # Set invalid username data
        idata = data.copy()
        idata['username'] = '******'
        resp = c.check_hypervisor_config(idata)
        self.assertFalse(resp['status'])
        self.assertEqual(resp['errors'],
                         {'username': '******'})

        # Set invalid session data
        idata = data.copy()
        idata['mode'] = 'invalidmode'
        resp = c.check_hypervisor_config(idata)
        self.assertFalse(resp['status'])
        self.assertEqual(resp['errors'], {'mode': 'Invalid session type'})
Exemplo n.º 2
0
    def test_14_get_submit_select_changes(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Configure hypervisor
        self.configure_hypervisor(c)
        # Start a session
        c.session_start(self.TEMPLATE_UUID, 'host', '0')
        # Check for empty changes
        resp = c.get_changes()
        self.assertEqual(resp, {})
        # Add some changes to database
        data = {
            'key': '/foo/bar',
            'schema': 'foo',
            'value': True,
            'signature': 'b'
        }
        c.submit_change('org.gnome.gsettings', data)
        # Check submitted changes
        resp = c.get_changes()
        self.assertEqual(
            resp, {u'org.gnome.gsettings': [[data['key'], data['value']]]})
        # Select change for profile
        resp = c.select_changes({'org.gnome.gsettings': [data['key']]})
        self.assertTrue(resp['status'])
Exemplo n.º 3
0
    def setUp(self):
        self.test_directory = tempfile.mkdtemp()

        self.args = {
            'database_path': os.path.join(self.test_directory, 'database.db'),
            'tmp_session_destroy_timeout': 60,
        }

        # Open service
        self.service = subprocess.Popen([
            os.environ['PYTHON'],
            os.path.join(os.environ['TOPSRCDIR'],
                         'tests/test_fcdbus_service.py'),
            self.test_directory,
        ])

        checks = 0
        while True:
            try:
                self.c = fcdbus.FleetCommanderDbusClient()
                self.c.get_public_key()
                break
            except:
                checks += 1
                if checks < self.MAX_DBUS_CHECKS:
                    time.sleep(0.1)
                else:
                    raise Exception('Test error: ' +
                                    'DBUS Service is taking too much to start')

        self.ssh = sshcontroller.SSHController()
        self.known_hosts_file = os.path.join(self.test_directory,
                                             'known_hosts')
Exemplo n.º 4
0
    def test_08_new_profile(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Create a new profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        self.assertTrue(resp['status'])
        uid = self.get_data_from_file(self.INDEX_FILE)[0]['url'].split('.')[0]
        self.assertEqual(resp['uid'], uid)
Exemplo n.º 5
0
 def test_09_delete_profile(self):
     c = fcdbus.FleetCommanderDbusClient()
     # Delete unexistent profile
     resp = c.delete_profile('fakeuid')
     self.assertTrue(resp['status'])
     # Delete existent profile
     resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
     resp = c.delete_profile(resp['uid'])
     self.assertTrue(resp['status'])
Exemplo n.º 6
0
 def test_02_get_hypervisor_config(self):
     c = fcdbus.FleetCommanderDbusClient()
     self.assertEqual(
         c.get_hypervisor_config(), {
             'pubkey': 'PUBLIC_KEY',
             'host': '',
             'username': '',
             'mode': 'system',
             'needcfg': True,
             'adminhost': '',
         })
Exemplo n.º 7
0
    def test_24_goa_accounts(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Create a profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        uid = resp['uid']

        PROFILE_FILE = os.path.join(self.args['profiles_dir'], uid + '.json')

        account1_id = 'Account account_fc_1432373432_0'
        account1 = {
            'Provider': 'provider',
            'MailEnabled': False,
            'DocumentsEnabled': True,
            'ContactsEnabled': False
        }

        account2_id = 'Account account_fc_1432883432_0'
        account2 = {
            'Provider': 'pizza_provider',
            'PepperoniEnabled': False,
            'CheeseEnabled': True,
            'HotdogEnabled': False
        }

        accounts = {account1_id: account1, account2_id: account2}

        # Add GOA accounts
        resp = c.goa_accounts(accounts, uid)
        self.assertTrue(resp['status'])
        profile = self.get_data_from_file(PROFILE_FILE)
        goa_accounts = profile['settings']['org.gnome.online-accounts']
        self.assertEqual(len(goa_accounts), 2)
        self.assertEqual(goa_accounts[account1_id], account1)
        self.assertEqual(goa_accounts[account2_id], account2)

        # Modify accounts
        del accounts[account1_id]
        resp = c.goa_accounts(accounts, uid)
        self.assertTrue(resp['status'])
        profile = self.get_data_from_file(PROFILE_FILE)
        goa_accounts = profile['settings']['org.gnome.online-accounts']
        self.assertEqual(len(goa_accounts), 1)
        self.assertEqual(goa_accounts[account2_id], account2)

        # Empty accounts
        accounts = {}
        resp = c.goa_accounts(accounts, uid)
        self.assertTrue(resp['status'])
        profile = self.get_data_from_file(PROFILE_FILE)
        goa_accounts = profile['settings']['org.gnome.online-accounts']
        self.assertEqual(len(goa_accounts), 0)
Exemplo n.º 8
0
    def test_22_clientdata_serving(self):
        c = fcdbus.FleetCommanderDbusClient()
        port = c.get_change_listener_port()

        # Request non existent profile
        with self.assertRaisesRegexp(urllib2.HTTPError,
                                     'HTTP Error 404: Not Found'):
            inexistentuid = '94484425290563468736752948271916980692'
            req = urllib2.Request('http://localhost:%s/%s.json' %
                                  (port, inexistentuid))
            f = urllib2.urlopen(req)
            response = f.read()
            f.close()

        # Create profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        uid = resp['uid']

        # Request index
        req = urllib2.Request('http://localhost:%s/index.json' % port)
        f = urllib2.urlopen(req)
        response = f.read()
        f.close()
        self.assertEqual(json.loads(response), [{
            'url': '%s.json' % uid,
            'displayName': 'foo'
        }])

        # Request applies
        req = urllib2.Request('http://localhost:%s/applies.json' % port)
        f = urllib2.urlopen(req)
        response = f.read()
        f.close()
        self.assertEqual(
            json.loads(response), {
                uid: {
                    'users': ['user1', 'user2', 'user3'],
                    'groups': ['group1', 'group2']
                }
            })

        # Request profile
        req = urllib2.Request('http://localhost:%s/%s.json' % (port, uid))
        f = urllib2.urlopen(req)
        response = f.read()
        f.close()
        self.assertEqual(json.loads(response), {
            'name': 'foo',
            'uid': uid,
            'description': 'bar',
            'settings': {}
        })
Exemplo n.º 9
0
    def test_06_add_known_host(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Check not known host
        resp = c.check_known_host('localhost')
        self.assertFalse(resp['status'])

        # Add host to known hosts
        c.add_known_host('localhost')

        # Check already known host
        resp = c.check_known_host('localhost')
        self.assertTrue(resp['status'])
Exemplo n.º 10
0
    def test_12_session_start(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Configure hypervisor
        self.configure_hypervisor(c)

        # Start session
        resp = c.session_start(self.TEMPLATE_UUID, 'host', '5')
        self.assertTrue(resp['status'])
        self.assertEqual(resp['port'], 0)

        # Try to start another session
        resp = c.session_start(self.TEMPLATE_UUID, 'host', '0')
        self.assertFalse(resp['status'])
        self.assertEqual(resp['error'], 'Session already started')
Exemplo n.º 11
0
    def test_11_list_domains(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Try to get domains without configuring hypervisor
        resp = c.list_domains()
        self.assertFalse(resp['status'])
        self.assertEqual(resp['error'], 'Error retrieving domains')

        # Configure hypervisor
        self.configure_hypervisor(c)

        # Get domains
        resp = c.list_domains()
        self.assertTrue(resp['status'])
        self.assertEqual(resp['domains'], MockLibVirtController.DOMAINS_LIST)
Exemplo n.º 12
0
    def test_20_get_profile_applies(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Create a profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        uid = resp['uid']

        # Get profiles data
        resp = c.get_profile_applies(uid)

        # Check profiles data
        self.assertTrue(resp['status'])
        self.assertEqual(resp['data'], {
            'users': ['user1', 'user2', 'user3'],
            'groups': ['group1', 'group2']
        })
Exemplo n.º 13
0
    def test_18_get_profiles(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Create a profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        uid = resp['uid']

        # Get profiles data
        resp = c.get_profiles()

        # Check profiles data
        self.assertTrue(resp['status'])
        self.assertEqual(resp['data'], [{
            'url': '%s.json' % uid,
            'displayName': 'foo'
        }])
Exemplo n.º 14
0
    def test_05_check_known_host(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Check not known host
        resp = c.check_known_host('localhost')
        self.assertFalse(resp['status'])
        self.assertEqual(resp['fprint'], '2048 SHA256:HASH localhost (RSA)\n')
        self.assertEqual(resp['keys'], 'localhost ssh-rsa KEY\n')

        # Add host to known hosts
        self.ssh.add_keys_to_known_hosts(self.known_hosts_file,
                                         'localhost ssh-rsa KEY\n')

        # Check already known host
        resp = c.check_known_host('localhost')
        self.assertTrue(resp['status'])
Exemplo n.º 15
0
    def test_16_empty_session_save(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Create a profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        uid = resp['uid']

        PROFILE_FILE = os.path.join(self.args['profiles_dir'], uid + '.json')

        # Configure hypervisor
        self.configure_hypervisor(c)
        # Start a session
        c.session_start(self.TEMPLATE_UUID, 'host', '0')

        # Save empty session
        resp = c.session_save(uid)
        self.assertTrue(resp['status'])
Exemplo n.º 16
0
    def test_07_install_public_key(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Test install with bad credentials
        resp = c.install_pubkey(
            'localhost',
            'username',
            'badpassword',
        )
        self.assertFalse(resp['status'])

        # Test install with correct credentials
        resp = c.install_pubkey(
            'localhost',
            'username',
            'password',
        )
        self.assertTrue(resp['status'])
Exemplo n.º 17
0
    def test_04_set_hypervisor_config(self):
        c = fcdbus.FleetCommanderDbusClient()

        data = {
            'host': 'localhost',
            'username': '******',
            'mode': 'session',
            'adminhost': ''
        }

        dataresp = data.copy()
        dataresp['pubkey'] = 'PUBLIC_KEY'

        # Set data
        resp = c.set_hypervisor_config(data)
        self.assertTrue(resp['status'])

        # Retrieve configuration and compare
        self.assertEqual(c.get_hypervisor_config(), dataresp)
Exemplo n.º 18
0
    def test_17_session_select_save(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Create a profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        uid = resp['uid']

        PROFILE_FILE = os.path.join(self.args['profiles_dir'], uid + '.json')

        # Configure hypervisor
        self.configure_hypervisor(c)
        # Start a session
        c.session_start(self.TEMPLATE_UUID, 'host', '0')

        gsettings = self.get_data_from_file(PROFILE_FILE)['settings']
        self.assertEqual(gsettings, {})

        # Submit a change
        change = {
            'key': '/foo/bar',
            'schema': 'foo',
            'value': True,
            'signature': 'b'
        }
        resp = c.submit_change('org.gnome.gsettings', change)
        self.assertTrue(resp['status'])

        # Select change
        resp = c.select_changes({'org.gnome.gsettings': ['/foo/bar']})
        self.assertTrue(resp['status'])

        # Save session
        resp = c.session_save(uid)
        self.assertTrue(resp['status'])

        gsettings = self.get_data_from_file(
            PROFILE_FILE)['settings']['org.gnome.gsettings']
        self.assertEqual(len(gsettings), 1)
        self.assertEqual(gsettings[0]['value'], True)
        self.assertEqual(gsettings[0]['signature'], 'b')

        self.assertEqual(gsettings[0]['key'], '/foo/bar')
Exemplo n.º 19
0
    def test_10_profile_props(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Create a profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        uid = resp['uid']

        PROFILE_FILE = os.path.join(self.args['profiles_dir'], uid + '.json')

        # Ammend name
        resp = c.profile_props({'profile-name': 'mynewname'}, uid)
        self.assertTrue(resp['status'])
        self.assertEqual(
            self.get_data_from_file(PROFILE_FILE)['name'], 'mynewname')

        # Check index file is being updated accordingly
        entry = {'url': '%s.json' % uid, 'displayName': 'wrongDisplayName'}
        for e in self.get_data_from_file(self.INDEX_FILE):
            if e['url'] == '%s.json' % uid:
                entry = e
                break
        self.assertEqual(entry['displayName'], 'mynewname')

        # Ammend description
        resp = c.profile_props({'profile-desc': 'somedesc'}, uid)
        self.assertTrue(resp['status'])
        self.assertEqual(
            self.get_data_from_file(PROFILE_FILE)['description'], 'somedesc')

        # Ammend users
        resp = c.profile_props({'users': 'u1,u2,u3'}, uid)
        self.assertTrue(resp['status'])
        self.assertEqual(
            self.get_data_from_file(self.APPLIES_FILE)[uid]['users'],
            ['u1', 'u2', 'u3'])

        # Ammend groups
        resp = c.profile_props({'groups': 'g1,g2,g3'}, uid)
        self.assertTrue(resp['status'])
        self.assertEqual(
            self.get_data_from_file(self.APPLIES_FILE)[uid]['groups'],
            ['g1', 'g2', 'g3'])
Exemplo n.º 20
0
    def test_13_session_stop(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Configure hypervisor
        self.configure_hypervisor(c)

        # Stop without previous session start
        resp = c.session_stop()
        self.assertFalse(resp['status'])
        self.assertEqual(resp['error'], 'There was no session started')

        # Stop previous started session
        c.session_start(self.TEMPLATE_UUID, 'host', '0')
        resp = c.session_stop()
        self.assertTrue(resp['status'])

        # Stop again
        resp = c.session_stop()
        self.assertFalse(resp['status'])
        self.assertEqual(resp['error'], 'There was no session started')
Exemplo n.º 21
0
    def setUp(self):
        self.test_directory = tempfile.mkdtemp()

        self.args = {
            'webservice_host': 'localhost',
            'webservice_port': '0',
            'state_dir': self.test_directory,
            'profiles_dir': os.path.join(self.test_directory, 'profiles'),
            'database_path': os.path.join(self.test_directory, 'database.db'),
            'tmp_session_destroy_timeout': 60,
        }

        self.INDEX_FILE = os.path.join(self.args['profiles_dir'], 'index.json')
        self.APPLIES_FILE = os.path.join(self.args['profiles_dir'],
                                         'applies.json')

        # Open service
        self.service = subprocess.Popen([
            os.path.join(os.environ['TOPSRCDIR'],
                         'tests/test_fcdbus_service.py'),
            self.test_directory,
        ])

        checks = 0
        while True:
            try:
                c = fcdbus.FleetCommanderDbusClient()
                c.get_public_key()
                break
            except:
                checks += 1
                if checks < self.MAX_DBUS_CHECKS:
                    time.sleep(0.1)
                else:
                    raise Exception(
                        'Test error: ' +
                        'DBUS Service is getting too much to start')

        self.ssh = sshcontroller.SSHController()
        self.known_hosts_file = os.path.join(self.args['state_dir'],
                                             'known_hosts')
Exemplo n.º 22
0
    def test_19_get_profile(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Create a profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        uid = resp['uid']

        # Get profiles data
        resp = c.get_profile(uid)

        # Check profiles data
        self.assertTrue(resp['status'])
        self.assertEqual(
            resp['data'], {
                'settings': {},
                'uid': uid,
                'name': 'foo',
                'description': 'bar',
                'users': ['user1', 'user2', 'user3'],
                'groups': ['group1', 'group2'],
            })
Exemplo n.º 23
0
    def test_24_is_session_active(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Configure hypervisor
        self.configure_hypervisor(c)

        # Check current session active without starting any
        resp = c.is_session_active()
        self.assertFalse(resp)

        # Check current session active after started current session
        print c.session_start(self.TEMPLATE_UUID, 'host', '5')
        resp = c.is_session_active()
        self.assertTrue(resp)

        # Check non existent session by its uuid
        resp = c.is_session_active('unkknown')
        self.assertFalse(resp)

        # Check existent session by its uuid
        resp = c.is_session_active('')
        self.assertTrue(resp)
Exemplo n.º 24
0
    def test_21_changes_listener(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Configure hypervisor
        self.configure_hypervisor(c)
        # Start a session
        c.session_start(self.TEMPLATE_UUID, 'host', '0')
        # Check for empty changes
        resp = c.get_changes()
        self.assertEqual(resp, {})

        # Obtain change listener port
        port = c.get_change_listener_port()

        # Submit changes via changes listener
        data = {
            'key': '/foo/bar',
            'schema': 'foo',
            'value': True,
            'signature': 'b'
        }
        jsondata = json.dumps(data)
        req = urllib2.Request(
            'http://localhost:%s/changes/submit/org.gnome.gsettings' % port,
            jsondata, {
                'Content-Type': 'application/json',
                'Content-Length': len(jsondata)
            })
        f = urllib2.urlopen(req)
        response = f.read()
        f.close()
        self.assertEqual(response, json.dumps({'status': 'ok'}))

        # Check submitted changes
        resp = c.get_changes()
        self.assertEqual(
            resp, {u'org.gnome.gsettings': [[data['key'], data['value']]]})
Exemplo n.º 25
0
    def test_15_highlighted_apps(self):
        c = fcdbus.FleetCommanderDbusClient()

        # Create a profile
        resp = c.new_profile(self.DUMMY_PROFILE_PAYLOAD)
        uid = resp['uid']

        PROFILE_FILE = os.path.join(self.args['profiles_dir'], uid + '.json')

        #        # Add GNOME Software overrides
        highlightedapps = ['foo.desktop', 'bar.desktop', 'baz.desktop']
        resp = c.highlighted_apps(highlightedapps, uid)
        self.assertTrue(resp['status'])
        profile = self.get_data_from_file(PROFILE_FILE)
        self.assertEqual(len(profile['settings']['org.gnome.gsettings']), 1)
        self.assertEqual(profile['settings']['org.gnome.gsettings'][0]['key'],
                         '/org/gnome/software/popular-overrides')
        self.assertEqual(
            profile['settings']['org.gnome.gsettings'][0]['value'],
            highlightedapps)

        # Modify overrides
        highlightedapps = ['foo.desktop']
        resp = c.highlighted_apps(highlightedapps, uid)
        self.assertTrue(resp['status'])
        profile = self.get_data_from_file(PROFILE_FILE)
        self.assertEqual(
            profile['settings']['org.gnome.gsettings'][0]["value"],
            highlightedapps)

        # Empty overrides
        highlightedapps = []
        resp = c.highlighted_apps(highlightedapps, uid)
        self.assertTrue(resp['status'])
        profile = self.get_data_from_file(PROFILE_FILE)
        self.assertEqual(len(profile['settings']['org.gnome.gsettings']), 0)
Exemplo n.º 26
0
 def test_01_get_public_key(self):
     c = fcdbus.FleetCommanderDbusClient()
     self.assertEqual(c.get_public_key(), 'PUBLIC_KEY')
Exemplo n.º 27
0
 def test_23_get_goa_providers(self):
     c = fcdbus.FleetCommanderDbusClient()
     resp = c.get_goa_providers()
     self.assertTrue(resp['status'])
     self.assertEqual(resp['providers'], self.DUMMY_GOA_PROVIDERS_DATA)
Exemplo n.º 28
0
 def test_00_get_debug_level(self):
     c = fcdbus.FleetCommanderDbusClient()
     self.assertEqual(c.get_debug_level(), 'debug')