예제 #1
0
    def restoreProfilesIni(self):
        # restore profiles.ini on the device to its previous state
        if not self.originalProfilesIni or not os.access(self.originalProfilesIni, os.F_OK):
            raise DMError('Unable to install original profiles.ini; file not found: %s',
                          self.originalProfilesIni)

        self._devicemanager.pushFile(self.originalProfilesIni, self.remoteProfilesIniPath)
예제 #2
0
    def _setup_remote_profile(self):
        """
        Copy profile and update the remote profiles ini file to point to the new profile
        """

        # copy the profile to the device.
        if self.dm.dirExists(self.remote_profile):
            self.dm.shellCheckOutput(['rm', '-r', self.remote_profile])

        try:
            self.dm.pushDir(self.profile.profile, self.remote_profile)
        except DMError:
            self.log.error(
                "Automation Error: Unable to copy profile to device.")
            raise

        extension_dir = os.path.join(self.profile.profile, 'extensions',
                                     'staged')
        if os.path.isdir(extension_dir):
            # Copy the extensions to the B2G bundles dir.
            # need to write to read-only dir
            subprocess.Popen([self.dm._adbPath, 'remount']).communicate()
            for filename in os.listdir(extension_dir):
                self.dm.shellCheckOutput(
                    ['rm', '-rf',
                     os.path.join(self.bundles_dir, filename)])
            try:
                self.dm.pushDir(extension_dir, self.bundles_dir)
            except DMError:
                self.log.error(
                    "Automation Error: Unable to copy extensions to device.")
                raise

        if not self.dm.fileExists(self.remote_profiles_ini):
            raise DMError(
                "The profiles.ini file '%s' does not exist on the device" %
                self.remote_profiles_ini)

        local_profiles_ini = tempfile.NamedTemporaryFile()
        self.dm.getFile(self.remote_profiles_ini, local_profiles_ini.name)

        config = ProfileConfigParser()
        config.read(local_profiles_ini.name)
        for section in config.sections():
            if 'Profile' in section:
                config.set(section, 'IsRelative', 0)
                config.set(section, 'Path', self.remote_profile)

        new_profiles_ini = tempfile.NamedTemporaryFile()
        config.write(open(new_profiles_ini.name, 'w'))

        self.backup_file(self.remote_profiles_ini)
        self.dm.pushFile(new_profiles_ini.name, self.remote_profiles_ini)

        # In B2G, user.js is always read from /data/local, not the profile
        # directory.  Backup the original user.js first so we can restore it.
        self.backup_file(self.user_js)
        self.dm.pushFile(os.path.join(self.profile.profile, "user.js"),
                         self.user_js)
예제 #3
0
 def remote_settings_db(self):
     if not self._remote_settings_db:
         for filename in self.dm.listFiles(self.remote_idb_dir):
             if filename.endswith('ssegtnti.sqlite'):
                 self._remote_settings_db = posixpath.join(self.remote_idb_dir, filename)
                 break
         else:
             raise DMError("Could not find settings db in '%s'!" % self.remote_idb_dir)
     return self._remote_settings_db
예제 #4
0
 def restoreProfile(self):
     """
     Restores the original user profile on the device.
     """
     if not self.profileDir:
         raise DMError("There is no profile to restore")
     #if we successfully copied the profile, make a backup of the file
     our_userJS = os.path.join(self.profileDir, "user.js")
     if os.path.exists(our_userJS):
         self.shellCheckOutput(
             ['dd', 'if=%s.orig' % self.userJS,
              'of=%s' % self.userJS])
     shutil.rmtree(self.profileDir)
     self.profileDir = None
예제 #5
0
    def waitForPort(self, timeout):
        """Waits for the marionette server to respond, until the timeout specified.

	:param timeout: Timeout parameter in seconds.
        """
        print "waiting for port"
        starttime = datetime.datetime.now()
        while datetime.datetime.now() - starttime < datetime.timedelta(
                seconds=timeout):
            try:
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                print "trying %s %s" % (self.marionettePort,
                                        self.marionetteHost)
                sock.connect((self.marionetteHost, self.marionettePort))
                data = sock.recv(16)
                sock.close()
                if '"from"' in data:
                    return True
            except socket.error:
                pass
            except Exception as e:
                raise DMError("Could not connect to marionette: %s" % e)
            time.sleep(1)
        raise DMError("Could not communicate with Marionette port")
예제 #6
0
 def restartB2G(self):
     """
     Restarts the b2g process on the device.
     """
     #restart b2g so we start with a clean slate
     if self.marionette and self.marionette.session:
         self.marionette.delete_session()
     self.shellCheckOutput(['stop', 'b2g'])
     # Wait for a bit to make sure B2G has completely shut down.
     tries = 10
     while "b2g" in self.shellCheckOutput(['ps', 'b2g']) and tries > 0:
         tries -= 1
         time.sleep(1)
     if tries == 0:
         raise DMError("Could not kill b2g process")
     self.shellCheckOutput(['start', 'b2g'])
예제 #7
0
    def setupDHCP(self, conn_type='eth0'):
        """
        Sets up networking.

        If conn_type is not set, it will assume eth0.
        """
        tries = 5
        while tries > 0:
            print "attempts left: %d" % tries
            try:
                self.shellCheckOutput(['netcfg', conn_type, 'dhcp'],
                                      timeout=10)
                if self.getIP():
                    return
            except DMError:
                pass
            tries = tries - 1
        raise DMError("Could not set up network connection")
예제 #8
0
    def setupDHCP(self, interfaces=['eth0', 'wlan0']):
        """Sets up networking.

        :param interfaces: Network connection types to try. Defaults to eth0 and wlan0.
        """
        all_interfaces = [line.split()[0] for line in \
                          self.shellCheckOutput(['netcfg']).splitlines()[1:]]
        interfaces_to_try = filter(lambda i: i in interfaces, all_interfaces)

        tries = 5
        print "Setting up DHCP..."
        while tries > 0:
            print "attempts left: %d" % tries
            try:
                for interface in interfaces_to_try:
                    self.shellCheckOutput(['netcfg', interface, 'dhcp'],
                                          timeout=10)
                    if self.getIP(interfaces=[interface]):
                        return
            except DMError:
                pass
            time.sleep(1)
            tries -= 1
        raise DMError("Could not set up network connection")