def test_config_object_reuse(self): """Call setup multiple times; parse the config file only once.""" test_config_filename = '/tmp/spoke_test_config_object_reuse.conf' test_config_file = open(test_config_filename, 'w') test_config_file.write(self.test_config) test_config_file.close() config.gConfig = None self.config = config.setup(test_config_filename) os.remove(test_config_filename) self.config = config.setup() self.assertTrue(self.config.has_section('testsection1'))
def __init__(self, methodName): """Setup config data and LDAP connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.log = logger.log_to_console() self.org_name = 'SpokeOrgTest' self.base_dn = self.config.get('DHCP', 'dhcp_basedn') self.search_scope = 2 # ldap.SUB self.retrieve_attr = None self.dhcp_server_class = 'dhcpServer' self.dhcp_service_class = 'dhcpService' self.dhcp_subnet_class = 'dhcpSubnet' self.dhcp_options_class = 'dhcpOptions' self.dhcp_group_class = 'dhcpGroup' self.dhcp_host_class = 'dhcpHost' self.dhcp_option_attr = 'dhcpOption' self.dhcp_statement_attr = 'dhcpStatement' self.dhcp_mac_attr = 'dhcpHWAddress' self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix') self.dhcp_server = 'test.dhcp.server.local' self.dhcp_group = 'testgroup' self.dhcp_host = 'testhost'
def __init__(self, methodName): """Setup config data and redis connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.ca_name = 'test-ca' self.ca_cn = 'Test Certificate Authority' self.ca_def_duration = self.config.get('CA', 'ca_def_duration') self.ca_base_dir = self.config.get('CA', 'ca_base_dir') self.ca_dir = os.path.join(self.ca_base_dir, self.ca_name) self.ca_key_rdir = self.config.get('CA', 'ca_key_dir') self.ca_cert_rdir = self.config.get('CA', 'ca_cert_dir') self.ca_req_rdir = self.config.get('CA', 'ca_req_dir') self.ca_cert_name = self.config.get('CA', 'ca_pub_cert') self.ca_key_name = self.config.get('CA', 'ca_priv_key') self.ca_index_name = self.config.get('CA', 'ca_index') self.ca_serial_name = self.config.get('CA', 'ca_serial') self.ca_key_dir = os.path.join(self.ca_dir, self.ca_key_rdir) self.ca_cert_dir = os.path.join(self.ca_dir, self.ca_cert_rdir) self.ca_req_dir = os.path.join(self.ca_dir, self.ca_req_rdir) self.ca_tree = [(self.ca_dir, [self.ca_cert_rdir, self.ca_key_rdir, self.ca_req_rdir], [self.ca_serial_name]), (self.ca_cert_dir, [], [self.ca_cert_name]), (self.ca_key_dir, [], [self.ca_key_name]), (self.ca_req_dir, [], [])] self.ca_key_file = os.path.join(self.ca_key_dir, self.ca_key_name) self.ca_cert_file = os.path.join(self.ca_cert_dir, self.ca_cert_name)
def __init__(self, org_name, user_id): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logger.setup(__name__) self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 0 #ldap.SCOPE_BASE self.org_attr = self.config.get('ATTR_MAP', 'org_attr', 'o') self.org_def_children = self.config.get('ATTR_MAP', \ 'org_def_children', 'people,groups,dns,hosts') self.org_children = self.org_def_children.split(',') self.user_login = self.config.get('ATTR_MAP', 'user_login', 'aenetAccountLoginName') self.user_id = user_id self.user = self._get_user(org_name, self.user_id) self.user_dn = self.user['data'][0].__getitem__(0) self.user_attrs = self.user['data'][0].__getitem__(1) self.user_classes = self.user_attrs['objectClass'] self.imap_class = self.config.get('ATTR_MAP', 'imap_class', 'aenetCyrus') self.imap_enable = self.config.get('ATTR_MAP', 'imap_enable', 'aenetCyrusEnabled') self.imap_mailbox = self.config.get('ATTR_MAP', 'imap_mailbox', 'aenetCyrusMailboxName') self.imap_domain = self.config.get('ATTR_MAP', 'imap_domain', 'aenetCyrusMailboxDomain') self.imap_partition = self.config.get('ATTR_MAP', 'imap_partition', 'aenetCyrusMailboxPartition') self.imap_partition_def = self.config.get('ATTR_MAP', \ 'imap_partition_def', 'partition-default') self.smtp_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix') self.smtp_address = self.config.get('ATTR_MAP', 'smtp_address', 'aenetPostfixEmailAccept') self.smtp_destination = self.config.get('ATTR_MAP', \ 'smtp_destination', 'aenetPostfixEmailDeliver') self.smtp_enable = self.config.get('ATTR_MAP', 'smtp_enable', 'aenetPostfixEnabled') self.smtp_pri_address = self.config.get('ATTR_MAP', \ 'smtp_pri_address', 'aenetPostfixEmailAddress')
def __init__(self, methodName): """Setup config data and LDAP connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.log = logger.log_to_console() self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 2 # ldap.SUB self.retrieve_attr = None self.container_attr = self.config.get('ATTR_MAP', 'container_attr') self.org_name = 'SpokeOrgPwdTest' self.org_attr = self.config.get('ATTR_MAP', 'org_attr') self.org_def_children = self.config.get('ATTR_MAP', 'org_def_children') self.org_children = self.org_def_children.split(',') self.user_container = self.config.get('ATTR_MAP', 'user_container') self.user_key = self.config.get('ATTR_MAP', 'user_key') self.user_login = self.config.get('ATTR_MAP', 'user_login') self.user_class = self.config.get('ATTR_MAP', 'user_class') self.user_name = self.config.get('ATTR_MAP', 'user_name') self.user_enable = self.config.get('ATTR_MAP', 'user_enable') self.user_def_pwd = self.config.get('ATTR_MAP', 'user_def_pwd') self.first = 'peter' self.last = 'password' self.user_id = self.first + self.last self.email_dom = 'test.user.loc' self.email_addr = self.user_id + '@' + self.email_dom
def __init__(self, org_name): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logger.setup(__name__) self.search_scope = 2 # ldap.SUB self.retrieve_attr = None self.org_name = org_name self.org = self._get_org(self.org_name) self.org_dn = self.org['data'][0].__getitem__(0) self.org_attrs = self.org['data'][0].__getitem__(1) self.org_classes = self.org_attrs['objectClass'] self.container_attr = self.config.get('ATTR_MAP', 'container_attr', 'ou') self.host_container = self.config.get('HOST', 'host_container', 'hosts') self.host_container_dn = '%s=%s,%s' % (self.container_attr, \ self.host_container, self.org_dn) self.host_class = self.config.get('HOST', 'host_class', 'aenetHost') self.host_key = self.config.get('HOST', 'host_key', 'cn') self.host_uuid_attr = self.config.get('HOST', 'host_uuid_attr', 'aenetHostUUID') self.host_name_attr = self.config.get('HOST', 'host_name_attr', 'aenetHostName') self.host_cpu_attr = self.config.get('HOST', 'host_cpu_attr', 'aenetHostCPU') self.host_mem_attr = self.config.get('HOST', 'host_mem_attr', 'aenetHostMem') self.host_extra_opts_attr = self.config.get('HOST', 'host_extra_opts_attr', 'aenetHostExtraOpts') self.host_family_attr = self.config.get('HOST', 'host_family_attr', 'aenetHostFamily') self.host_network_layout_attr = self.config.get('HOST', 'host_network_layout_attr', 'aenetHostNetworkLayout') self.host_storage_layout_attr = self.config.get('HOST', 'host_storage_layout_attr', 'aenetHostStorageLayout') self.host_type_attr = self.config.get('HOST', 'host_type_attr', 'aenetHostType')
def __init__(self, dhcp_server, group=None, host=None): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logger.setup(self.__module__) self.base_dn = self.config.get('DHCP', 'dhcp_basedn') self.search_scope = 2 # ldap.SUB self.retrieve_attr = None self.dhcp_options_class = 'dhcpOptions' self.dhcp_service_class = 'dhcpService' self.dhcp_option_attr = 'dhcpOption' self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config') self.dhcp_server = dhcp_server self.service_name = self.dhcp_server + self.dhcp_conf_suffix self.dhcp_service = self._get_dhcp_service(self.dhcp_server) self.dhcp_service_dn = self.dhcp_service['data'][0].__getitem__(0) self.target_dn = self.dhcp_service_dn if group is not None: self.dhcp_group_name = group self.dhcp_group = self._get_dhcp_group(self.dhcp_server, \ self.dhcp_group_name) self.dhcp_group_dn = self.dhcp_group['data'][0].__getitem__(0) self.target_dn = self.dhcp_group_dn if host is not None: self.dhcp_host_name = host self.dhcp_host = self._get_dhcp_host(self.dhcp_server, \ self.dhcp_group_name, self.dhcp_host_name) self.dhcp_host_dn = self.dhcp_host['data'][0].__getitem__(0) self.target_dn = self.dhcp_host_dn
def __init__(self, methodName): """Setup config data and LDAP connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 2 # ldap.SCOPE_SUBTREE self.retrieve_attr = None self.org_name = 'SpokeUserTest' self.org_attr = self.config.get('ATTR_MAP', 'org_attr') self.org_def_children = self.config.get('ATTR_MAP', 'org_def_children') self.org_children = self.org_def_children.split(',') self.container_attr = self.config.get('ATTR_MAP', 'container_attr') self.user_container = self.config.get('ATTR_MAP', 'user_container') self.user_key = self.config.get('ATTR_MAP', 'user_key') self.user_login = self.config.get('ATTR_MAP', 'user_login') self.user_class = self.config.get('ATTR_MAP', 'user_class') self.user_name = self.config.get('ATTR_MAP', 'user_name') self.user_enable = self.config.get('ATTR_MAP', 'user_enable') self.first = 'timmy' self.last = 'test' self.user_id = self.first self.email_dom = 'test.user.loc' self.email_addr = self.user_id + '@' + self.email_dom self.org_dn = '%s=%s,%s' % (self.org_attr, self.org_name, self.base_dn) self.user_container_dn = '%s=%s,%s' % (self.container_attr, \ self.user_container, self.org_dn)
def __init__(self, methodName): """Setup config data and LDAP connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.log = logger.log_to_console() self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 2 # ldap.SCOPE_SUBTREE self.retrieve_attr = None self.org_name = 'SpokeListTest' self.org_attr = self.config.get('ATTR_MAP', 'org_attr') self.org_def_children = self.config.get('ATTR_MAP', 'org_def_children') self.org_children = self.org_def_children.split(',') self.container_attr = self.config.get('ATTR_MAP', 'container_attr') self.list_container = self.config.get('ATTR_MAP', 'user_container') self.list_class = self.config.get('ATTR_MAP', 'smtp_class') self.list_key = self.config.get('ATTR_MAP', 'user_key') self.list_address_attr = self.config.get('ATTR_MAP', 'smtp_address') self.list_destination_attr = self.config.get('ATTR_MAP', 'smtp_destination') self.list_enable_attr = self.config.get('ATTR_MAP', 'smtp_enable') self.list_pri_address_attr = self.config.get('ATTR_MAP', 'smtp_pri_address') self.list_address = '*****@*****.**' self.list_member = '*****@*****.**'
def __init__(self, org_name): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logging.getLogger(__name__) self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 2 #ldap.SCOPE_SUB self.org_name = org_name self.org = self._get_org(self.org_name) self.org_dn = self.org['data'][0].__getitem__(0) self.org_attrs = self.org['data'][0].__getitem__(1) self.org_classes = self.org_attrs['objectClass'] self.container_attr = self.config.get('ATTR_MAP', 'container_attr', 'ou') self.list_container = self.config.get('ATTR_MAP', 'user_container', 'people') self.list_key = self.config.get('ATTR_MAP', 'user_key', 'uid') self.list_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix') self.list_address_attr = self.config.get('ATTR_MAP', 'smtp_address', 'aenetPostfixEmailAccept') self.list_destination_attr = self.config.get('ATTR_MAP', \ 'smtp_destination', 'aenetPostfixEmailDeliver') self.list_enable_attr = self.config.get('ATTR_MAP', 'smtp_enable', 'aenetPostfixEnabled') self.list_pri_address_attr = self.config.get('ATTR_MAP', \ 'smtp_pri_address', 'aenetPostfixEmailAddress') self.retrieve_attr = [self.list_address_attr]
def __init__(self, org_name, user_id): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logging.getLogger(__name__) self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 0 #ldap.SCOPE_BASE self.org_attr = self.config.get('ATTR_MAP', 'org_attr', 'o') self.org_def_children = self.config.get('ATTR_MAP', \ 'org_def_children', 'people,groups,dns,hosts') self.org_children = self.org_def_children.split(',') self.user_login = self.config.get('ATTR_MAP', 'user_login', 'aenetAccountLoginName') self.user_id = user_id self.user = self._get_user(org_name, self.user_id) self.user_dn = self.user['data'][0].__getitem__(0) self.user_attrs = self.user['data'][0].__getitem__(1) self.user_classes = self.user_attrs['objectClass'] self.imap_class = self.config.get('ATTR_MAP', 'imap_class', 'aenetCyrus') self.imap_enable = self.config.get('ATTR_MAP', 'imap_enable', 'aenetCyrusEnabled') self.imap_mailbox = self.config.get('ATTR_MAP', 'imap_mailbox', 'aenetCyrusMailboxName') self.imap_domain = self.config.get('ATTR_MAP', 'imap_domain', 'aenetCyrusMailboxDomain') self.imap_partition = self.config.get('ATTR_MAP', 'imap_partition', 'aenetCyrusMailboxPartition') self.imap_partition_def = self.config.get('ATTR_MAP', \ 'imap_partition_def', 'partition-default') self.smtp_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix') self.smtp_address = self.config.get('ATTR_MAP', 'smtp_address', 'aenetPostfixEmailAccept') self.smtp_destination = self.config.get('ATTR_MAP', \ 'smtp_destination', 'aenetPostfixEmailDeliver') self.smtp_enable = self.config.get('ATTR_MAP', 'smtp_enable', 'aenetPostfixEnabled') self.smtp_pri_address = self.config.get('ATTR_MAP', \ 'smtp_pri_address', 'aenetPostfixEmailAddress')
def __init__(self, methodName): """Setup config data and redis connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.log = logger.log_to_console() self.ca_name = 'test-ca' self.ca_cn = 'Test Certificate Authority' self.ca_def_duration = self.config.get('CA', 'ca_def_duration') self.ca_base_dir = self.config.get('CA', 'ca_base_dir') self.ca_dir = os.path.join(self.ca_base_dir, self.ca_name) self.ca_key_rdir = self.config.get('CA', 'ca_key_dir') self.ca_cert_rdir = self.config.get('CA', 'ca_cert_dir') self.ca_req_rdir = self.config.get('CA', 'ca_req_dir') self.ca_cert_name = self.config.get('CA', 'ca_pub_cert') self.ca_key_name = self.config.get('CA', 'ca_priv_key') self.ca_index_name = self.config.get('CA', 'ca_index') self.ca_serial_name = self.config.get('CA', 'ca_serial') self.ca_key_dir = os.path.join(self.ca_dir, self.ca_key_rdir) self.ca_cert_dir = os.path.join(self.ca_dir, self.ca_cert_rdir) self.ca_req_dir = os.path.join(self.ca_dir, self.ca_req_rdir) self.ca_tree = [ (self.ca_dir, [self.ca_cert_rdir, self.ca_key_rdir, self.ca_req_rdir], [self.ca_serial_name]), (self.ca_cert_dir, [], [self.ca_cert_name]), (self.ca_key_dir, [], [self.ca_key_name]), (self.ca_req_dir, [], []) ] self.ca_key_file = os.path.join(self.ca_key_dir, self.ca_key_name) self.ca_cert_file = os.path.join(self.ca_cert_dir, self.ca_cert_name)
def __init__(self, org_name, list_address): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logging.getLogger(__name__) self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 0 #ldap.SCOPE_BASE self.org_name = org_name self.list_address = self._validate_input(list_address) self.list_name, self.list_domain = self.list_address.split('@') self.list = self._get_list(self.org_name, self.list_address) self.list_dn = self.list['data'][0].__getitem__(0) self.list_attrs = self.list['data'][0].__getitem__(1) self.list_classes = self.list_attrs['objectClass'] self.list_key = self.config.get('ATTR_MAP', 'user_key', 'uid') self.list_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix') self.list_address_attr = self.config.get('ATTR_MAP', 'smtp_address', 'aenetPostfixEmailAccept') self.list_destination_attr = self.config.get('ATTR_MAP', \ 'smtp_destination', 'aenetPostfixEmailDeliver') self.list_enable_attr = self.config.get('ATTR_MAP', 'smtp_enable', 'aenetPostfixEnabled') self.list_pri_address_attr = self.config.get('ATTR_MAP', \ 'smtp_pri_address', 'aenetPostfixEmailAddress') self.retrieve_attr = [self.list_destination_attr]
def __init__(self): """Bind to LDAP directory, return an ldap object.""" self.config = config.setup() self.log = logger.setup(__name__) self.search_scope = ldap.SCOPE_SUBTREE #(2) self.server = self.config.get('LDAP', 'server') self.port = self.config.get('LDAP', 'port', '389') self.bind_dn = self.config.get('LDAP', 'binddn') self.start_tls = self.config.get('LDAP', 'start_tls', False) self.bind_password = self.config.get('LDAP', 'bindpw') try: self.LDAP = ldap.initialize('ldap://%s:%s' % (self.server, self.port)) self.LDAP.protocol_version = 3 #ldap.VERSION3 if self.start_tls: self.LDAP.start_tls_s() self.LDAP.simple_bind_s(self.bind_dn, self.bind_password) self.log.debug('Bound to LDAP server %s:%s as %s' % (self.server, self.port, self.bind_dn)) except ldap.LDAPError: trace = traceback.format_exc() msg = 'Failed to bind to LDAP server %s:%s as %s' % \ (self.server,self.port, self.bind_dn) raise error.SpokeLDAPError(msg, trace) except Exception: trace = traceback.format_exc() msg = 'Unknown error' raise error.SpokeError(msg, trace)
def __init__(self, org_name): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logging.getLogger(__name__) self.search_scope = 2 #ldap.SCOPE_SUBTREE self.retrieve_attr = None self.org_name = org_name self.org = self._get_org(self.org_name) self.org_dn = self.org['data'][0].__getitem__(0) self.org_attrs = self.org['data'][0].__getitem__(1) self.org_classes = self.org_attrs['objectClass'] self.org_attr = self.config.get('ATTR_MAP', 'org_attr', 'o') self.container_attr = self.config.get('ATTR_MAP', 'container_attr', 'ou') self.user_login = self.config.get('ATTR_MAP', 'user_login', 'aenetAccountLoginName') self.user_class = self.config.get('ATTR_MAP', 'user_class', 'aenetAccount') self.user_key = self.config.get('ATTR_MAP', 'user_key', 'uid') self.user_name = self.config.get('ATTR_MAP', 'user_name', 'aenetAccountDisplayName') self.user_enable = self.config.get('ATTR_MAP', 'user_enable', 'aenetAccountEnabled') self.user_container = self.config.get('ATTR_MAP', 'user_container', 'people')
def __init__(self, ca_name): """Get config, setup logging.""" self.config = config.setup() self.log = logger.log_to_console() self.ca_name = common.is_shell_safe(ca_name) self.ca_base_dir = self.config.get('CA', 'ca_base_dir') self.ca_dir = os.path.join(self.ca_base_dir, self.ca_name) self.ca_key_rdir = self.config.get('CA', 'ca_key_dir', 'private') self.ca_cert_rdir = self.config.get('CA', 'ca_cert_dir', 'certs') self.ca_req_rdir = self.config.get('CA', 'ca_req_dir', 'reqs') self.ca_cert_name = self.config.get('CA', 'ca_pub_cert', 'ca-cert.pem') self.ca_bundle_name = self.config.get('CA', 'ca_bundle', 'ca-bundle.pem') self.ca_req_name = self.config.get('CA', 'ca_req', 'ca-req.pem') self.ca_key_name = self.config.get('CA', 'ca_priv_key', 'ca-key.pem') self.ca_index_name = self.config.get('CA', 'ca_index', 'index') self.ca_serial_name = self.config.get('CA', 'ca_serial', 'serial') self.ca_cert_dir = os.path.join(self.ca_dir, self.ca_cert_rdir) self.ca_key_dir = os.path.join(self.ca_dir, self.ca_key_rdir) self.ca_req_dir = os.path.join(self.ca_dir, self.ca_req_rdir) self.ca_cert_file = os.path.join(self.ca_cert_dir, self.ca_cert_name) self.ca_bundle_file = os.path.join(self.ca_base_dir, self.ca_bundle_name) self.ca_key_file = os.path.join(self.ca_key_dir, self.ca_key_name) self.ca_req_file = os.path.join(self.ca_req_dir, self.ca_req_name) self.ca_index_file = os.path.join(self.ca_cert_dir, self.ca_index_name) self.ca_serial_file = os.path.join(self.ca_dir, self.ca_serial_name) self.ca_key = os.path.join(self.ca_key_dir, self.ca_key_file) self.ca_cert = os.path.join(self.ca_cert_dir, self.ca_cert_file) self.req_dirs = [ self.ca_base_dir, self.ca_dir, self.ca_key_dir, self.ca_req_dir, self.ca_cert_dir ] self.req_files = [ self.ca_index_file, self.ca_serial_file, self.ca_key_file, self.ca_cert_file ] try: ca_cert = X509.load_cert(self.ca_cert_file, format=1) self.ca_cn = ca_cert.get_subject().CN self.ca_cert_as_pem = ca_cert.as_pem() except: msg = 'CA cert file %s does not exist' % self.ca_cert_file self.log.debug(msg) self.ca_country = self.config.get('CA', 'ca_country', 'GB') try: self.ca_state = self.config.get('CA', 'ca_state') except: self.ca_state = None self.ca_locality = self.config.get('CA', 'ca_locality', 'London') self.ca_org = self.config.get('CA', 'ca_org', 'Acme Ltd') self.ca_ou = self.config.get('CA', 'ca_ou', 'Certificate Services') self.ca_email = self.config.get('CA', 'ca_email', '*****@*****.**') self.ca_def_duration = self.config.get('CA', 'ca_def_duration', 1095) self.ca_keypass = self.config.get('CA', 'ca_keypass', '') # Try to get some more info from req/cert files if they are present self.ca_info = self._get_ca_info() try: self.ca_cn = self.ca_info['ca_cn'] except:pass try: self.ca_cert_as_pem = self.ca_info['ca_cert_as_pem'] except:pass
def __init__(self, vg_name=None): """Get config, setup logging.""" self.config = config.setup() self.log = logging.getLogger(__name__) if not vg_name: vg_name = self.config.get('LVM', 'lv_def_vg_name') self.vg_name = common.is_shell_safe(vg_name) self.lv_units = self.config.get('LVM', 'lv_units', 'g')
def __init__(self, cn, requester, signer=None): """Get config, setup logging.""" self.config = config.setup() self.log = logger.setup(__name__) self.reqca = self._get_ca(requester) if signer: self.signca = self._get_ca(signer) else: self.signca = self.reqca
def __init__(self, vm_name): """Get config and setup logging.""" self.config = config.setup() self.log = logging.getLogger(__name__) def _error_handler(self, err): msg = "Ignoring Libvirt error %s)" % err pass # Prevent libvirt errors from reaching the console libvirt.registerErrorHandler(_error_handler, None)
def __init__(self, cn, requester, signer=None): """Get config, setup logging.""" self.config = config.setup() self.log = logger.log_to_console() self.reqca = self._get_ca(requester) if signer: self.signca = self._get_ca(signer) else: self.signca = self.reqca
def __init__(self, org_name, domain_name): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logging.getLogger(__name__) self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 2 # ldap.SUB self.retrieve_attr = None self.org_name = org_name self.org = self._get_org(self.org_name) self.org_dn = self.org['data'][0].__getitem__(0) self.org_attrs = self.org['data'][0].__getitem__(1) self.org_classes = self.org_attrs['objectClass'] self.dns_cont_attr = self.config.get('DNS', 'dns_cont_attr', 'ou') self.dns_cont_name = self.config.get('DNS', 'dns_cont_name', 'dns') self.dns_cont_class = self.config.get('ATTR_MAP', \ 'container_class', 'organizationalUnit') self.dns_zone_name_attr = self.config.get('DNS', 'dns_zone_attr', 'zoneName') self.dns_zone_class = self.config.get('DNS', 'dns_zone_class', 'dNSZone') self.dns_resource_attr = self.config.get('DNS', 'dns_resource_attr', 'relativeDomainName') self.dns_record_class = self.config.get('DNS', 'dns_record_class', 'IN') self.dns_default_ttl = self.config.get('DNS', 'dns_default_ttl', '86400') self.dns_min_ttl = self.config.get('DNS', 'dns_min_ttl', '3600') self.dns_serial_start = self.config.get('DNS', 'dns_serial_start', '1') self.dns_slave_refresh = self.config.get('DNS', 'dns_slave_refresh', '3600') self.dns_slave_retry = self.config.get('DNS', 'dns_slave_retry', '600') self.dns_slave_expire = self.config.get('DNS', 'dns_slave_expire', '86400') self.dns_ns_attr = self.config.get('DNS', 'dns_ns_attr', 'nSRecord') self.dns_soa_attr = self.config.get('DNS', 'dns_soa_attr', 'sOARecord') self.dns_a_attr = self.config.get('DNS', 'dns_a_attr', 'aRecord') self.dns_cname_attr = self.config.get('DNS', 'dns_cname_attr', 'cNAMERecord') self.dns_mx_attr = self.config.get('DNS', 'dns_mx_attr', 'mXRecord') self.dns_txt_attr = self.config.get('TXT', 'dns_txt_attr', 'tXTRecord') self.dns_ptr_attr = self.config.get('PTR', 'dns_ptr_attr', 'pTRRecord') self.dns_type_attrs = { 'SOA': self.dns_soa_attr, 'NS': self.dns_ns_attr, 'A': self.dns_a_attr, 'CNAME': self.dns_cname_attr, 'MX': self.dns_mx_attr, 'TXT': self.dns_txt_attr, 'PTR': self.dns_ptr_attr } self.domain_name = common.validate_domain(domain_name) self.dns_dn = '%s=%s,%s' % (self.dns_cont_attr, self.dns_cont_name, \ self.org_dn) self.zone_dn = '%s=%s,%s' % (self.dns_zone_name_attr, \ self.domain_name, self.dns_dn)
def __init__(self, methodName): """Setup config data and redis connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.subnet = '192.168.1.0' self.mask = 24 self.ip_ldap_key = self.config.get('IP', 'ip_ldap_key')
def __init__(self, methodName): """Setup config data and Cyrus connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.user = self.config.get('IMAP', 'user') self.sep = '/' self.mbx_name = '*****@*****.**'
def __init__(self): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logger.setup(__name__) self.base_dn = self.config.get('DHCP', 'dhcp_basedn') self.search_scope = 2 # ldap.SUB self.retrieve_attr = None self.dhcp_server_class = 'dhcpServer' self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config')
def test_write_read_log_message(self): """Write message to log file; read it back.""" logger.gLog = None self.config = config.setup(self.test_config_filename) self.log = logger.setup(self.__module__) test_phrase = 'This is a Spoke logger test' self.log.critical(test_phrase) lf = open(self.test_log_filename, 'r') lines = lf.readlines() lf.close() res = lines[-1].find(test_phrase) self.assert_(res > -1)
def __init__(self, dhcp_server): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logger.setup(self.__module__) self.base_dn = self.config.get('DHCP', 'dhcp_basedn') self.search_scope = 2 # ldap.SUB self.retrieve_attr = None self.dhcp_group_class = 'dhcpGroup' self.dhcp_options_class = 'dhcpOptions' self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config') self.service_name = dhcp_server + self.dhcp_conf_suffix self.service_dn = 'cn=%s,%s' % (self.service_name, self.base_dn)
def __init__(self, methodName): """Define test config data, write, parse and return config object.""" unittest.TestCase.__init__(self, methodName) self.test_log_filename = '/tmp/spoke-test.log' test_config = ''' [LOGGING] log_filename = /tmp/spoke-test.log log_level = debug ''' self.test_config_filename = '/tmp/spoke_test_logger.conf' test_config_file = open(self.test_config_filename, 'w') test_config_file.write(test_config) test_config_file.close() self.config = config.setup(self.test_config_filename)
def __init__(self, dhcp_server): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logger.setup(self.__module__) self.base_dn = self.config.get('DHCP', 'dhcp_basedn') self.search_scope = 2 # ldap.SUB self.retrieve_attr = None self.dhcp_subnet_class = 'dhcpSubnet' self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config') self.dhcp_server = dhcp_server self.dhcp_service_name = self.dhcp_server + self.dhcp_conf_suffix self.dhcp_service = self._get_dhcp_service(self.dhcp_server) self.dhcp_service_dn = self.dhcp_service['data'][0].__getitem__(0)
def __init__(self, methodName): """Setup config data and LDAP connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.log = logger.log_to_console() self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 2 # ldap.SCOPE_SUBTREE self.retrieve_attr = None self.org_name = 'spokehosttest' self.org_attr = self.config.get('ATTR_MAP', 'org_attr') self.org_def_children = self.config.get('ATTR_MAP', 'org_def_children') self.org_children = self.org_def_children.split(',') self.org_dn = '%s=%s,%s' % (self.org_attr, self.org_name, self.base_dn) self.container_attr = self.config.get('ATTR_MAP', 'container_attr') self.host_container = self.config.get('HOST', 'host_container') self.host_container_dn = '%s=%s,%s' % (self.container_attr, \ self.host_container, self.org_dn) self.host_class = self.config.get('HOST', 'host_class') self.host_key = self.config.get('HOST', 'host_key') self.host_uuid_attr = self.config.get('HOST', 'host_uuid_attr') self.host_name_attr = self.config.get('HOST', 'host_name_attr') self.host_cpu_attr = self.config.get('HOST', 'host_cpu_attr') self.host_mem_attr = self.config.get('HOST', 'host_mem_attr') self.host_extra_opts_attr = self.config.get('HOST', 'host_extra_opts_attr') self.host_family_attr = self.config.get('HOST', 'host_family_attr') self.host_network_layout_attr = self.config.get( 'HOST', 'host_network_layout_attr') self.host_storage_layout_attr = self.config.get( 'HOST', 'host_storage_layout_attr') self.host_type_attr = self.config.get('HOST', 'host_type_attr') self.next_uuid_attr = self.config.get('UUID', 'next_uuid_attr') self.next_uuid_dn = self.config.get('UUID', 'next_uuid_dn') self.next_uuid_start = self.config.get('UUID', 'next_uuid_start') self.host_name = 'testhost' self.host_uuid = '1' self.host_mem = '256' self.host_mem_kb = '%s' % (int(self.host_mem) * 1024) self.host_cpu = '1' self.host_extra_opts = 'test' self.host_family = 'xen' self.host_storage_layout = 'basic' self.host_network_layout = 'with_internet' self.host_type = 'full'
def __init__(self, methodName): """Setup config data and LDAP connection.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.log = logger.log_to_console() self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 2 # ldap.SCOPE_SUBTREE self.retrieve_attr = None self.org_name = 'spokehosttest' self.org_attr = self.config.get('ATTR_MAP', 'org_attr') self.org_def_children = self.config.get('ATTR_MAP', 'org_def_children') self.org_children = self.org_def_children.split(',') self.org_dn = '%s=%s,%s' % (self.org_attr, self.org_name, self.base_dn) self.container_attr = self.config.get('ATTR_MAP', 'container_attr') self.host_container = self.config.get('HOST', 'host_container') self.host_container_dn = '%s=%s,%s' % (self.container_attr, \ self.host_container, self.org_dn) self.host_class = self.config.get('HOST', 'host_class') self.host_key = self.config.get('HOST', 'host_key') self.host_uuid_attr = self.config.get('HOST', 'host_uuid_attr') self.host_name_attr = self.config.get('HOST', 'host_name_attr') self.host_cpu_attr = self.config.get('HOST', 'host_cpu_attr') self.host_mem_attr = self.config.get('HOST', 'host_mem_attr') self.host_extra_opts_attr = self.config.get('HOST', 'host_extra_opts_attr') self.host_family_attr = self.config.get('HOST', 'host_family_attr') self.host_network_layout_attr = self.config.get('HOST', 'host_network_layout_attr') self.host_storage_layout_attr = self.config.get('HOST', 'host_storage_layout_attr') self.host_type_attr = self.config.get('HOST', 'host_type_attr') self.next_uuid_attr = self.config.get('UUID', 'next_uuid_attr') self.next_uuid_dn = self.config.get('UUID', 'next_uuid_dn') self.next_uuid_start = self.config.get('UUID', 'next_uuid_start') self.host_name = 'testhost' self.host_uuid = '1' self.host_mem = '256' self.host_mem_kb = '%s' % (int(self.host_mem)*1024) self.host_cpu = '1' self.host_extra_opts = 'test' self.host_family = 'xen' self.host_storage_layout = 'basic' self.host_network_layout = 'with_internet' self.host_type = 'full'
def __init__(self, methodName): """Setup config data.""" unittest.TestCase.__init__(self, methodName) common_config = '../../contrib/spoke.conf' custom_config = '/tmp/spoke.conf' config_files = (common_config, custom_config) self.config = config.setup(config_files) self.tftp_root = self.config.get('TFTP', 'tftp_root') self.tftp_conf_dir = self.config.get('TFTP', 'tftp_conf_dir') self.tftp_mac_prefix = self.config.get('TFTP', 'tftp_mac_prefix') self.mac = '00:0C:29:57:3B:31' self.template = 'testfile.template' self.run_id = 23123132 self.tftp_dir = self.tftp_root + "/" + self.tftp_conf_dir + "/"
def __init__(self, org_name): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logger.setup(self.__module__) self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 0 #ldap.SCOPE_BASE self.org_name = org_name self.org = self._get_org(self.org_name) self.org_dn = self.org['data'][0].__getitem__(0) self.org_attrs = self.org['data'][0].__getitem__(1) self.org_classes = self.org_attrs['objectClass'] self.smtp_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix') self.smtp_domain = self.config.get('ATTR_MAP', 'smtp_domain', 'aenetPostfixDomain') self.retrieve_attr = [self.smtp_domain]
def __init__(self, org_name): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logging.getLogger(__name__) self.base_dn = self.config.get('LDAP', 'basedn') self.search_scope = 0 #ldap.SCOPE_BASE self.org_name = org_name self.org = self._get_org(self.org_name) self.org_dn = self.org['data'][0].__getitem__(0) self.org_attrs = self.org['data'][0].__getitem__(1) self.org_classes = self.org_attrs['objectClass'] self.smtp_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix') self.smtp_domain = self.config.get('ATTR_MAP', 'smtp_domain', 'aenetPostfixDomain') self.retrieve_attr = [self.smtp_domain]
def test_spoke_LDAP_missing_server_config_key(self): """Parse config with missing ldap server key; raise ConfigError.""" config.gConfig = None self.test_nosrvr_config = ''' [LDAP] key1=value1 key2 = value 2 ''' self.test_nosrvr_config_filename = '/tmp/spoke_test_nosrvr_config.conf' test_nosrvr_config_file = open(self.test_nosrvr_config_filename, 'w') test_nosrvr_config_file.write(self.test_nosrvr_config) test_nosrvr_config_file.close() self.config = config.setup(self.test_nosrvr_config_filename) self.assertRaises(error.ConfigError,self.config.get,'LDAP','server') os.remove(self.test_nosrvr_config_filename)
def __init__(self): """Get config and setup loggings.""" self.config = config.setup() self.log = logging.getLogger(__name__) #This block gets interface and interface type from config file self._lookupInterfaces() #And this one does the same for disks. self._lookupDisks() self.search_headers = self.config.get('VM', 'search_headers', 'name,uuid') self.headers = self.search_headers.split(',') def _error_handler(self, err): msg = "Ignoring Libvirt error %s)" % err pass # Prevent libvirt errors from reaching the console libvirt.registerErrorHandler(_error_handler, None)
def __init__(self, dhcp_server, group_name): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logger.setup(self.__module__) self.base_dn = self.config.get('DHCP', 'dhcp_basedn') self.search_scope = 2 # ldap.SUB self.retrieve_attr = None self.dhcp_host_class = 'dhcpHost' self.dhcp_options_class = 'dhcpOptions' self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config') self.dhcp_server = dhcp_server self.dhcp_group_name = group_name group = self._get_dhcp_group(self.dhcp_server, self.dhcp_group_name) self.dhcp_group_dn = group['data'][0].__getitem__(0)
def __init__(self, tftp_root=None): self.config = config.setup() self.log = logging.getLogger(__name__) self.type = 'TFTP config' if not tftp_root: tftp_root = self.config.get('TFTP', 'tftp_root') self.tftp_root = common.validate_filename(tftp_root) self.tftp_conf_dir = self.config.get('TFTP', 'tftp_conf_dir', 'pxelinux.cfg') self.tftp_mac_prefix = self.config.get('TFTP', 'tftp_mac_prefix', '01') # Add the delimiter (makes life easier when concating strings self.tftp_prefix = self.tftp_mac_prefix + '-' #check file exists in the TFTP directory self.tftp_dir = self.tftp_root + "/" + self.tftp_conf_dir + "/" if not os.path.isdir(self.tftp_dir): msg = "TFTP config directory %s not found" % self.tftp_dir raise error.NotFound, msg
def __init__(self): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logger.setup(__name__) self.search_scope = 0 #ldap.SCOPE_BASE self.next_uuid_attr = self.config.get('UUID','next_uuid_attr', 'aenetHostUUID') self.base_dn = self.config.get('LDAP','basedn') self.next_uuid_dn = self.config.get('UUID','next_uuid_dn', self.base_dn) self.next_uuid_class = self.config.get('UUID','next_uuid_class', 'aenetNextUUID') self.next_uuid_start = self.config.get('UUID','next_uuid_start', 1) self.next_uuid = self._get_next_uuid_dn()['data'] self.next_uuid_attrs = self.next_uuid[0].__getitem__(1) self.next_uuid_classes = self.next_uuid_attrs['objectClass'] self.retrieve_attr = [self.next_uuid_attr] self.filter = '%s=*' % self.next_uuid_attr
def __init__(self): """Get config, setup logging and cyrus connection.""" self.config = config.setup() self.log = logging.getLogger(__name__) server = self.config.get('IMAP', 'server') port = int(self.config.get('IMAP', 'port', 143)) self.user = self.config.get('IMAP', 'user') password = self.config.get('IMAP', 'password') self.mailbox_group = self.config.get('IMAP', 'mailbox_group', 'user') self.sep = '/' try: self.imap = imaplib.IMAP4(server, port) except imaplib.socket.error: trace = traceback.format_exec() msg = '%s: %s' % ('IMAP connection error') raise error.SpokeIMAPError(msg, trace) self.imap.login(self.user, password)
def __init__(self, org_name, user_id): """Get config, setup logging and LDAP connection.""" SpokeLDAP.__init__(self) self.config = config.setup() self.log = logging.getLogger(__name__) self.org_name = org_name self.user_id = user_id self.user = self._get_user(self.org_name, self.user_id) self.user_dn = self.user['data'][0].__getitem__(0) self.user_attrs = self.user['data'][0].__getitem__(1) self.user_classes = self.user_attrs['objectClass'] self.svn_class = self.config.get('VCS', 'svn_class', 'aenetSubversion') self.svn_repo_attr = self.config.get('VCS', 'svn_repo_attr', 'aenetSubversionRepos') self.svn_enable_attr = self.config.get('VCS', 'svn_enable_attr', 'aenetSubversionEnabled') self.retrieve_attr = [self.svn_repo_attr, self.svn_enable_attr] self.filter = self.svn_repo_attr + '=*' self.search_scope = 2 # ldap.SUB