Ejemplo n.º 1
0
    def load(self):
        ''' Loading data '''
        self.logger.debug('load - BEGIN')
        data = GecosAccessData()

        # Check previous saved data (in memory cache)
        if self.previous_saved_data is not None:
            return self.previous_saved_data

        # Get data from data file
        jsonUtil = JSONUtil()
        json_data = jsonUtil.loadJSONFromFile(self.data_file)
        if json_data is not None:

            data.set_login(json_data['gcc_username'].encode('utf-8'))
            data.set_url(json_data['uri_gcc'].encode('utf-8'))

            # Password is not stored!
            data.set_password(None)

        if data.get_url() is None or data.get_url().strip() == '':
            data = None

        self.logger.debug('load - END')
        return data
    def runTest(self):
        dao = GecosAccessDataDAO()

        print "Try to load original data..."
        originalData = dao.load()

        print "Set test data..."
        newData = GecosAccessData()
        newData.set_url('test_url')
        newData.set_login('test_login')
        dao.save(newData)

        print "Load and check test data..."
        newData = dao.load()

        self.assertEqual(newData.get_url(), 'test_url')
        self.assertEqual(newData.get_login(), 'test_login')

        wddao = WorkstationDataDAO()
        wd = wddao.load()

        dao.delete(newData)
        self.assertFalse(os.path.isfile('/etc/gcc.control'))

        if originalData is not None:
            print "Restore original data..."
            dao.save(originalData)
            wddao.save(wd)
Ejemplo n.º 3
0
    def setup(self, *args):
        ''' Setup action '''

        self.logger.debug("setup")
        if self.get_data() is None:
            self.set_data(GecosAccessData())
        self.get_data() \
            .set_url(self.getElementById('url_entry').get_text())
        self.get_data() \
            .set_login(self.getElementById('login_entry').get_text())
        self.get_data() \
            .set_password(self.getElementById('password_entry').get_text())

        self.controller.setup()
Ejemplo n.º 4
0
    def patternSearch(self, *args):
        ''' Searching by pattern '''

        self.logger.debug("patternSearch")

        if self.get_gecos_access_data() is None:
            self.set_gecos_access_data(GecosAccessData())

        self.get_gecos_access_data().set_url(self.gecosCCurlEntry.get_text())
        self.get_gecos_access_data().set_login(
            self.gecosCCuserEntry.get_text())
        self.get_gecos_access_data().set_password(
            self.gecosCCpassEntry.get_text())

        res = self.controller.patternSearch(self.searchFilterEntry.get_text())
        self.loadOUCombo(res)
Ejemplo n.º 5
0
    def disconnect(self, *args):
        ''' Disconnect from Gecos Control Center '''

        self.logger.debug("disconnect")

        if self.get_gecos_access_data() is None:
            self.set_gecos_access_data(GecosAccessData())

        self.get_gecos_access_data().set_url(self.gecosCCurlEntry.get_text())
        self.get_gecos_access_data().set_login(
            self.gecosCCuserEntry.get_text())
        self.get_gecos_access_data().set_password(
            self.gecosCCpassEntry.get_text())

        self.get_workstation_data()
        if self.get_workstation_data() is None:
            self.set_workstation_data(WorkstationData())
        self.get_workstation_data().set_name(
            self.workstationNameEntry.get_text())
        self.get_workstation_data().set_ou(self.getOUComboValue())

        self.controller.disconnect(self.disconnectCheckbox.get_active())
Ejemplo n.º 6
0
    from gecosws_config_assistant.util.GecosCC import GecosCC
    from gecosws_config_assistant.util.SSLUtil import SSLUtil
    from gecosws_config_assistant.util.GemUtil import GemUtil
    from gecosws_config_assistant.util.Template import Template
    from gecosws_config_assistant.dto.GecosAccessData import GecosAccessData
    from gecosws_config_assistant.dto.WorkstationData import WorkstationData
    from gecosws_config_assistant.dao.WorkstationDataDAO import WorkstationDataDAO
    from gecosws_config_assistant.firstboot_lib.firstbootconfig import get_data_file

    # List of GEMS required to run GECOS
    necessary_gems = [
        'json', 'rest-client', 'activesupport:4.2.11.1', 'netaddr'
    ]
    nsis.setvar('6', "false")
    gecosAccessData = GecosAccessData()
    gecosAccessData.set_url(nsis.getvar('$0'))
    gecosAccessData.set_login(nsis.getvar('$1'))
    gecosAccessData.set_password(nsis.getvar('$2'))
    gecoscc = GecosCC()

    workstationDataDao = WorkstationDataDAO()
    workstationData = workstationDataDao.load()

    conf = json.loads(os.environ["AUTOCFGJSON"])

    # Get client.pem from server
    logging.info("Get client.pem from server")
    gecosCC = GecosCC()

    rekey = False
Ejemplo n.º 7
0
#  $1 = User
#  $2 = Password
#
# OUT parameters:
#  $4 = true if the credentials are valid or false otherwise

try:
    import logging
    logging.basicConfig(filename=os.environ["PYLOGFILE"], level=logging.DEBUG)
    logging.info('========== Validate GECOS credentials ==============')

    from gecosws_config_assistant.util.GecosCC import GecosCC
    from gecosws_config_assistant.util.SSLUtil import SSLUtil
    from gecosws_config_assistant.dto.GecosAccessData import GecosAccessData

    gecosAccessData = GecosAccessData()
    gecosAccessData.set_url(nsis.getvar('$0'))
    gecosAccessData.set_login(nsis.getvar('$1'))
    gecosAccessData.set_password(nsis.getvar('$2'))
    gecoscc = GecosCC()

    # TODO: Disable certificate validation without asking
    SSLUtil.disableSSLCertificatesVerification()

    isOk = gecoscc.validate_credentials(gecosAccessData)
    nsis.setvar('4', str(isOk))

    if gecoscc.last_request_content is not None:
        os.environ["AUTOCFGJSON"] = gecoscc.last_request_content

except:
Ejemplo n.º 8
0
    def runTest(self):
        gecosCC = GecosCC()

        # Test with valid Gecos CC credentials
        badCredentials = GecosAccessData()
        self.assertFalse(gecosCC.validate_credentials(badCredentials),
                         'Error validating empty credentials')

        badCredentials.set_login('nonexistenuser')
        self.assertFalse(gecosCC.validate_credentials(badCredentials),
                         'Error validating credentials without password')

        badCredentials.set_password('badpassword')
        self.assertFalse(gecosCC.validate_credentials(badCredentials),
                         'Error validating credentials without URL')

        badCredentials.set_url('this is not a URL!')
        self.assertFalse(gecosCC.validate_credentials(badCredentials),
                         'Error validating credentials with a malformed URL')

        badCredentials.set_url('http://www.google.es')
        self.assertFalse(gecosCC.validate_credentials(badCredentials),
                         'Error validating credentials with a bad address')

        badCredentials.set_url('http://192.168.0.15/')
        self.assertFalse(
            gecosCC.validate_credentials(badCredentials),
            'Error validating credentials with a non existent user')

        badCredentials.set_login('superuser')
        self.assertFalse(gecosCC.validate_credentials(badCredentials),
                         'Error validating credentials with a bad password')

        # Test with valid Gecos CC credentials
        validCredentials = GecosAccessData()
        validCredentials.set_url('http://192.168.0.15/')
        validCredentials.set_login('superuser')
        validCredentials.set_password('yzsrhysa')
        self.assertTrue(gecosCC.validate_credentials(validCredentials),
                        'Error validating credentials')

        # Check autoconfiguration JSON
        conf = gecosCC.get_json_autoconf(validCredentials)
        self.assertNotEqual(conf, None, "None returned!")
        print "AutoSetup JSON:", json.dumps(conf)

        # Check ou search
        result = gecosCC.search_ou_by_text(validCredentials, '')
        self.assertTrue(isinstance(result, (list, tuple)),
                        'OUs must be a list!')

        for res in result:
            result2 = gecosCC.search_ou_by_text(validCredentials, res[1])
            self.assertTrue(isinstance(result2, (list, tuple)),
                            'OU: %s must exist!' % (res[1]))

        # Get all computer names
        result = gecosCC.get_computer_names(validCredentials)
        self.assertTrue(isinstance(result, (list, tuple)),
                        'Computer names must be a list!')

        # Chef node registration
        self.assertFalse(
            gecosCC.is_registered_chef_node(validCredentials, 'test'))

        private_key = gecosCC.register_chef_node(validCredentials, 'test')
        self.assertNotEqual(private_key, False, "No private key returned!")
        self.assertTrue(
            gecosCC.is_registered_chef_node(validCredentials, 'test'))

        # Chef node re-registering
        private_key = gecosCC.reregister_chef_node(validCredentials, 'test')
        self.assertNotEqual(private_key, False, "No private key returned!")
        self.assertTrue(
            gecosCC.is_registered_chef_node(validCredentials, 'test'))

        # Chef node unregistering
        self.assertTrue(gecosCC.unregister_chef_node(validCredentials, 'test'))
        self.assertFalse(
            gecosCC.is_registered_chef_node(validCredentials, 'test'))
Ejemplo n.º 9
0
    def runTest(self):
        obj = GecosAccessData()
        
        obj.set_url('test_url')
        self.assertEqual(obj.get_url(), 'test_url')
        self.assertEqual(obj.url, 'test_url')

        obj.set_login('test_login')
        self.assertEqual(obj.get_login(), 'test_login')
        self.assertEqual(obj.login, 'test_login')

        obj.set_password('test_password')
        self.assertEqual(obj.get_password(), 'test_password')
        self.assertEqual(obj.password, 'test_password')
Ejemplo n.º 10
0
    def runTest(self):
        obj = SystemStatus()

        # Network interfaces
        obj.set_network_interfaces([])
        self.assertEqual(obj.get_network_interfaces(), [])
        self.assertEqual(obj.networkInterfaces, [])

        networkInterfaces = []
        networkInterfaces.append(NetworkInterface())
        obj.set_network_interfaces(networkInterfaces)
        self.assertEqual(obj.networkInterfaces, networkInterfaces)

        with self.assertRaises(TypeError):
            obj.set_network_interfaces('wrong data!')

        with self.assertRaises(TypeError):
            obj.set_network_interfaces(None)

        with self.assertRaises(TypeError):
            obj.set_network_interfaces(['wrong data!'])

        # Time server
        timeServer = NTPServer()
        obj.set_time_server(timeServer)
        self.assertEqual(obj.get_time_server(), timeServer)
        self.assertEqual(obj.timeServer, timeServer)

        obj.set_time_server(None)
        self.assertEqual(obj.get_time_server(), None)

        with self.assertRaises(TypeError):
            obj.set_time_server('wrong data!')

        # Workstation data
        workstationData = WorkstationData()
        obj.set_workstation_data(workstationData)
        self.assertEqual(obj.get_workstation_data(), workstationData)
        self.assertEqual(obj.workstationData, workstationData)

        obj.set_workstation_data(None)
        self.assertEqual(obj.get_workstation_data(), None)

        with self.assertRaises(TypeError):
            obj.set_workstation_data('wrong data!')

        # GECOS access data
        gecosAccessData = GecosAccessData()
        obj.set_gecos_access_data(gecosAccessData)
        self.assertEqual(obj.get_gecos_access_data(), gecosAccessData)
        self.assertEqual(obj.gecosAccessData, gecosAccessData)

        obj.set_gecos_access_data(None)
        self.assertEqual(obj.get_gecos_access_data(), None)

        with self.assertRaises(TypeError):
            obj.set_gecos_access_data('wrong data!')

        # Local users
        obj.set_local_users([])
        self.assertEqual(obj.get_local_users(), [])
        self.assertEqual(obj.localUsers, [])

        localUsers = []
        localUsers.append(LocalUser())
        obj.set_local_users(localUsers)
        self.assertEqual(obj.localUsers, localUsers)

        with self.assertRaises(TypeError):
            obj.set_local_users('wrong data!')

        with self.assertRaises(TypeError):
            obj.set_local_users(None)

        with self.assertRaises(TypeError):
            obj.set_local_users(['wrong data!'])

        # User authentication method
        userAuthenticationMethod = LocalUsersAuthMethod()
        obj.set_user_authentication_method(userAuthenticationMethod)
        self.assertEqual(obj.get_user_authentication_method(),
                         userAuthenticationMethod)
        self.assertEqual(obj.userAuthenticationMethod,
                         userAuthenticationMethod)

        obj.set_user_authentication_method(None)
        self.assertEqual(obj.get_user_authentication_method(), None)

        with self.assertRaises(TypeError):
            obj.set_user_authentication_method('wrong data!')