• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import os, glob, re, logging
2from autotest_lib.client.bin import test, utils, package
3from autotest_lib.client.bin.test_config import config_loader
4from autotest_lib.client.common_lib import error
5
6class lsb_dtk(test.test):
7    """
8    This autotest module runs the LSB test suite.
9
10    @copyright: IBM 2008
11    @author: Pavan Naregundi (pnaregun@in.ibm.com)
12    @author: Lucas Meneghel Rodrigues (lucasmr@br.ibm.com)
13    """
14    version = 1
15    def initialize(self, config):
16        arch = utils.get_current_kernel_arch()
17        if arch in ['i386', 'i486', 'i586', 'i686', 'athlon']:
18            self.arch = 'ia32'
19        elif arch == 'ppc':
20            self.arch = 'ppc32'
21        elif arch in ['s390', 's390x', 'ia64', 'x86_64', 'ppc64']:
22            self.arch = arch
23        else:
24            e_msg = 'Architecture %s not supported by LSB' % arch
25            raise error.TestError(e_msg)
26
27        self.config = config_loader(config, self.tmpdir)
28        self.cachedir = os.path.join(self.bindir, 'cache')
29        if not os.path.isdir(self.cachedir):
30            os.makedirs(self.cachedir)
31
32        self.packages_installed = False
33        self.libraries_linked = False
34
35
36
37    def install_lsb_packages(self):
38        if not self.packages_installed:
39            # First, we download the LSB DTK manager package, worry about
40            # installing it later
41            dtk_manager_arch = self.config.get('dtk-manager', 'arch-%s' % self.arch)
42            dtk_manager_url = self.config.get('dtk-manager',
43                                         'tarball_url') % dtk_manager_arch
44            if not dtk_manager_url:
45                raise error.TestError('Could not get DTK manager URL from'
46                                      ' configuration file')
47
48            dtk_md5 = self.config.get('dtk-manager', 'md5-%s' % self.arch)
49            if dtk_md5:
50                logging.info('Caching LSB DTK manager RPM')
51                dtk_manager_pkg = utils.unmap_url_cache(self.cachedir,
52                                                        dtk_manager_url,
53                                                        dtk_md5)
54            else:
55                raise error.TestError('Could not find DTK manager package md5,'
56                                      ' cannot cache DTK manager tarball')
57
58            # Get LSB tarball, cache it and uncompress under autotest srcdir
59            if self.config.get('lsb', 'override_default_url') == 'no':
60                lsb_url = self.config.get('lsb', 'tarball_url') % self.arch
61            else:
62                lsb_url = self.config.get('lsb', 'tarball_url_alt') % self.arch
63            if not lsb_url:
64                raise error.TestError('Could not get LSB URL from configuration'
65                                      ' file')
66            md5_key = 'md5-%s' % self.arch
67            lsb_md5 = self.config.get('lsb', md5_key)
68            if lsb_md5:
69                logging.info('Caching LSB tarball')
70                lsb_pkg = utils.unmap_url_cache(self.cachedir, lsb_url, lsb_md5)
71            else:
72                raise error.TestError('Could not find LSB package md5, cannot'
73                                      ' cache LSB tarball')
74
75            utils.extract_tarball_to_dir(lsb_pkg, self.srcdir)
76
77            # Lets load a file that contains the list of RPMs
78            os.chdir(self.srcdir)
79            if not os.path.isfile('inst-config'):
80                raise IOError('Could not find file with package info,'
81                              ' inst-config')
82            rpm_file_list = open('inst-config', 'r')
83            pkg_pattern = re.compile('[A-Za-z0-9_.-]*[.][r][p][m]')
84            lsb_pkg_list = []
85            for line in rpm_file_list.readlines():
86                try:
87                    # We will install lsb-dtk-manager separately, so we can remove
88                    # it from the list of packages
89                    if not 'lsb-dtk-manager' in line:
90                        line = re.findall(pkg_pattern, line)[0]
91                        lsb_pkg_list.append(line)
92                except:
93                    # If we don't get a match, no problem
94                    pass
95
96            # Lets figure out the host distro
97            distro_pkg_support = package.os_support()
98            if os.path.isfile('/etc/debian_version') and \
99            distro_pkg_support['dpkg']:
100                logging.debug('Debian based distro detected')
101                if distro_pkg_support['conversion']:
102                    logging.debug('Package conversion supported')
103                    distro_type = 'debian-based'
104                else:
105                    raise EnvironmentError('Package conversion not supported.'
106                                           'Cannot handle LSB package'
107                                           ' installation')
108            elif distro_pkg_support['rpm']:
109                logging.debug('Red Hat based distro detected')
110                distro_type = 'redhat-based'
111            else:
112                logging.error('OS does not seem to be red hat or debian based')
113                raise EnvironmentError('Cannot handle LSB package installation')
114
115            # According to the host distro detection, we can install the packages
116            # using the list previously assembled
117            if distro_type == 'redhat-based':
118                logging.info('Installing LSB RPM packages')
119                package.install(dtk_manager_pkg)
120                for lsb_rpm in lsb_pkg_list:
121                    package.install(lsb_rpm, nodeps=True)
122            elif distro_type == 'debian-based':
123                logging.info('Remember that you must have the following lsb'
124                             ' compliance packages installed:')
125                logging.info('lsb-core lsb-cxx lsb-graphics lsb-desktop lsb-qt4'
126                             ' lsb-languages lsb-multimedia lsb-printing')
127                logging.info('Converting and installing LSB packages')
128                dtk_manager_dpkg = package.convert(dtk_manager_pkg, 'dpkg')
129                package.install(dtk_manager_dpkg)
130                for lsb_rpm in lsb_pkg_list:
131                    lsb_dpkg = package.convert(lsb_rpm, 'dpkg')
132                    package.install(lsb_dpkg, nodeps=True)
133
134            self.packages_installed = True
135
136
137    def link_lsb_libraries(self):
138        if not self.libraries_linked:
139            logging.info('Linking LSB libraries')
140            libdir_key = 'libdir-%s' % self.arch
141            os_libdir = self.config.get('lib', libdir_key)
142            if not os_libdir:
143                raise TypeError('Could not find OS lib dir from conf file')
144            lib_key = 'lib-%s' % self.arch
145            lib_list_raw = self.config.get('lib', lib_key)
146            if not lib_list_raw:
147                raise TypeError('Could not find library list from conf file')
148            lib_list = eval(lib_list_raw)
149
150            # Remove any previous ld-lsb*.so symbolic links
151            lsb_libs = glob.glob('%s/ld-lsb*.so*' % os_libdir)
152            for lib in lsb_libs:
153                os.remove(lib)
154
155            # Get the base library that we'll use to recreate the symbolic links
156            system_lib = glob.glob('%s/ld-2*.so*' % os_libdir)[0]
157
158            # Now just link the system lib that we just found to each one of the
159            # needed LSB libraries that we provided on the conf file
160            for lsb_lib in lib_list:
161                # Get the library absolute path
162                lsb_lib = os.path.join(os_libdir, lsb_lib)
163                # Link the library system_lib -> lsb_lib
164                os.symlink(system_lib, lsb_lib)
165
166            self.libraries_linked = True
167
168
169    def run_once(self, args = 'all'):
170        self.install_lsb_packages()
171        self.link_lsb_libraries()
172
173        main_script_path = self.config.get('lsb', 'main_script_path')
174
175        logfile = os.path.join(self.resultsdir, 'lsb.log')
176        log_arg = '-r %s' % (logfile)
177        args = args + ' ' + log_arg
178        cmd = os.path.join(self.srcdir, main_script_path) + ' ' + args
179
180        logging.info('Executing LSB main test script')
181        utils.system(cmd)
182