Esempio 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
Esempio n. 2
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')
Esempio n. 3
0
    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
    if (gecosCC.is_registered_chef_node(gecosAccessData,
                                        workstationData.get_node_name())):
        # re-register
Esempio n. 4
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'))