Exemplo n.º 1
0
    def _verify_launched(self):
        """Poll on expected http://<host>:<port> until it is reachable
        Assert that the response contains the expected version information
        """

        resp_obj = self._wait_until_reachable()
        log_info(resp_obj)

        # .NET Microsoft Windows 10.12/x86_64 1.3.1-build0013/5d1553d
        running_version = resp_obj["vendor"]["version"]

        if not running_version.startswith(".NET Microsoft Windows"):
            raise LiteServError("Invalid platform running!")

        #  ['.NET', 'Microsoft', 'Windows', '10', 'Enterprise', 'x64', '1.4.0', 'build0043', '5cfe25b']
        running_version_parts = re.split("[ /-]", running_version)
        running_version = running_version_parts[6]
        running_build = int(running_version_parts[7].strip("build"))
        running_version_composed = "{}-{}".format(running_version,
                                                  running_build)

        if self.version_build != running_version_composed:
            raise LiteServError(
                "Expected version does not match actual version: Expected={}  Actual={}"
                .format(self.version_build, running_version_composed))
Exemplo n.º 2
0
    def remove(self):
        """Removes the LiteServ application from the running device
        """
        output = subprocess.check_output(
            ["adb", "uninstall", "com.couchbase.liteservandroid"])
        if output.strip() != "Success":
            log_info(output)
            raise LiteServError("Error. Could not remove app.")

        output = subprocess.check_output(
            ["adb", "shell", "pm", "list", "packages"])
        if "com.couchbase.liteservandroid" in output:
            raise LiteServError("Error uninstalling app!")

        log_info("LiteServ removed from {}".format(self.host))
Exemplo n.º 3
0
    def stop(self):
        """
        Stops a .NET listener on a remote windows machine via ansible and pulls logs.
        """

        # The package structure for LiteServ is different pre 1.4. Handle for this case
        if has_dot_net4_dot_5(self.version_build):
            binary_path = "couchbase-lite-net-msft-{}-liteserv/net45/LiteServ.exe".format(
                self.version_build)
        else:
            binary_path = "couchbase-lite-net-msft-{}-liteserv/LiteServ.exe".format(
                self.version_build)

        log_full_path = "{}/{}".format(os.getcwd(), self.logfile)

        log_info("Stoping {} on windows maching ...".format(binary_path))
        log_info("Pulling logs to {} ...".format(log_full_path))

        status = self.ansible_runner.run_ansible_playbook(
            "stop-liteserv-windows.yml",
            extra_vars={
                "binary_path": binary_path,
                "log_full_path": log_full_path
            })
        if status != 0:
            raise LiteServError("Could not start Liteserv")
Exemplo n.º 4
0
 def _verify_launched(self):
     """ Poll on expected http://<host>:<port> until it is reachable
     Assert that the response contains the expected version information
     """
     resp_obj = self._wait_until_reachable()
     log_info(resp_obj)
     if resp_obj["version"] != self.version_build:
         raise LiteServError(
             "Expected version: {} does not match running version: {}".
             format(self.version_build, resp_obj["version"]))
Exemplo n.º 5
0
    def start(self, logfile_name):
        """
        1. Starts a LiteServ with logging to provided logfile file object.
           The running LiteServ process will be stored in the self.process property.
        2. The method will poll on the endpoint to make sure LiteServ is available.
        3. The expected version will be compared with the version reported by http://<host>:<port>
        4. eturn the url of the running LiteServ
        """

        self._verify_not_running()

        self.logfile = logfile_name

        process_args = ["--port", str(self.port), "--dir", "."]

        if self.storage_engine == "ForestDB" or self.storage_engine == "ForestDB+Encryption":
            process_args.append("--storage")
            process_args.append("ForestDB")
        else:
            process_args.append("--storage")
            process_args.append("SQLite")

        if self.storage_engine == "SQLCipher" or self.storage_engine == "ForestDB+Encryption":
            log_info("Using Encryption ...")
            db_flags = []
            for db_name in REGISTERED_CLIENT_DBS:
                db_flags.append("--dbpassword")
                db_flags.append("{}=pass".format(db_name))
            process_args.extend(db_flags)

        # The package structure for LiteServ is different pre 1.4. Handle for this case
        if has_dot_net4_dot_5(self.version_build):
            binary_path = "couchbase-lite-net-msft-{}-liteserv/net45/LiteServ.exe".format(
                self.version_build)
        else:
            binary_path = "couchbase-lite-net-msft-{}-liteserv/LiteServ.exe".format(
                self.version_build)

        joined_args = " ".join(process_args)
        log_info("Starting LiteServ {} with: {}".format(
            binary_path, joined_args))

        # Start LiteServ via Ansible on remote machine
        status = self.ansible_runner.run_ansible_playbook(
            "start-liteserv-msft.yml",
            extra_vars={
                "binary_path": binary_path,
                "launch_args": joined_args,
            })
        if status != 0:
            raise LiteServError("Could not stop Liteserv")

        self._verify_launched()

        return "http://{}:{}".format(self.host, self.port)
Exemplo n.º 6
0
    def install(self):
        """Install the apk to running Android device or emulator"""

        if self.storage_engine == "SQLite":
            apk_name = "couchbase-lite-android-liteserv-SQLite-{}-debug.apk".format(
                self.version_build)
        else:
            apk_name = "couchbase-lite-android-liteserv-SQLCipher-ForestDB-Encryption-{}-debug.apk".format(
                self.version_build)

        apk_path = "{}/{}".format(BINARY_DIR, apk_name)
        log_info("Installing: {}".format(apk_path))

        # If and apk is installed, attempt to remove it and reinstall.
        # If that fails, raise an exception
        max_retries = 1
        count = 0
        while True:

            if count > max_retries:
                raise LiteServError(".apk install failed!")
            try:
                output = subprocess.check_output(
                    ["adb", "install", "-r", apk_path])
                break
            except Exception as e:
                if "INSTALL_FAILED_ALREADY_EXISTS" in e.message or "INSTALL_FAILED_UPDATE_INCOMPATIBLE" in e.message:
                    # Apk may be installed, remove and retry install
                    log_info("Trying to remove....")
                    self.remove()
                    count += 1
                    continue
                else:
                    # Install succeeded, continue
                    break

        output = subprocess.check_output(
            ["adb", "shell", "pm", "list", "packages"])
        if "com.couchbase.liteservandroid" not in output:
            raise LiteServError("Failed to install package: {}".format(output))

        log_info("LiteServ installed to {}".format(self.host))
Exemplo n.º 7
0
    def __init__(self, version_build, host, port, storage_engine):

        # Initialize baseclass properies
        super(LiteServNetMsft, self).__init__(version_build, host, port,
                                              storage_engine)

        if "LITESERV_MSFT_HOST_USER" not in os.environ:
            raise LiteServError(
                "Make sure you define 'LITESERV_MSFT_HOST_USER' as the windows user for the host you are targeting"
            )

        if "LITESERV_MSFT_HOST_PASSWORD" not in os.environ:
            raise LiteServError(
                "Make sure you define 'LITESERV_MSFT_HOST_PASSWORD' as the windows user for the host you are targeting"
            )

        # Create config for LiteServ Windows host
        ansible_liteserv_mfst_target_lines = [
            "[windows]",
            "win1 ansible_host={}".format(host),
            "[windows:vars]",
            "ansible_user={}".format(os.environ["LITESERV_MSFT_HOST_USER"]),
            "ansible_password={}".format(
                os.environ["LITESERV_MSFT_HOST_PASSWORD"]),
            "ansible_port=5986",
            "ansible_connection=winrm",
            "# The following is necessary for Python 2.7.9+ when using default WinRM self-signed certificates:",
            "ansible_winrm_server_cert_validation=ignore",
        ]

        ansible_liteserv_mfst_target_string = "\n".join(
            ansible_liteserv_mfst_target_lines)
        log_info("Writing: {}".format(ansible_liteserv_mfst_target_string))
        config_location = "resources/liteserv_configs/net-msft"

        with open(config_location, "w") as f:
            f.write(ansible_liteserv_mfst_target_string)

        self.ansible_runner = AnsibleRunner(config=config_location)
Exemplo n.º 8
0
    def install(self):
        """
        Installs needed packages on Windows host and removes any existing service wrappers for LiteServ
        """
        # The package structure for LiteServ is different pre 1.4. Handle for this case
        if has_dot_net4_dot_5(self.version_build):
            directory_path = "couchbase-lite-net-msft-{}-liteserv/net45/LiteServ.exe".format(
                self.version_build)
        else:
            directory_path = "couchbase-lite-net-msft-{}-liteserv/LiteServ.exe".format(
                self.version_build)

        status = self.ansible_runner.run_ansible_playbook(
            "install-liteserv-windows.yml",
            extra_vars={"directory_path": directory_path})

        if status != 0:
            raise LiteServError("Failed to install Liteserv on Windows host")
Exemplo n.º 9
0
    def download(self, version_build=None):
        """
        1. Downloads the LiteServ.zip package from latestbuild to the remote Windows host to Desktop\LiteServ\
        2. Extracts the package and removes the zip
        """
        if version_build is not None:
            self.version_build = version_build
        version, build = version_and_build(self.version_build)
        download_url = "{}/couchbase-lite-net/{}/{}/LiteServ.zip".format(
            LATEST_BUILDS, version, build)
        package_name = "couchbase-lite-net-msft-{}-liteserv".format(
            self.version_build)

        # Download LiteServ via Ansible on remote machine
        status = self.ansible_runner.run_ansible_playbook(
            "download-liteserv-msft.yml",
            extra_vars={
                "download_url": download_url,
                "package_name": package_name
            })

        if status != 0:
            raise LiteServError(
                "Failed to download LiteServ package on remote machine")
Exemplo n.º 10
0
    def install(self):
        """Installs / launches LiteServ on iOS simulator
        Default is iPhone 7 Plus
        """
        self.device = "iPhone-7-Plus"
        package_name = "LiteServ-iOS.app"
        app_dir = "LiteServ-iOS"

        if self.storage_engine == "SQLCipher":
            package_name = "LiteServ-iOS-SQLCipher.app"
            app_dir = "LiteServ-iOS-SQLCipher"

        self.app_path = "{}/{}/{}".format(BINARY_DIR, app_dir, package_name)
        output = subprocess.check_output([
            "ios-sim", "--devicetypeid", self.device, "start"
        ])

        log_info("Installing: {}".format(self.app_path))
        # Launch the simulator and install the app
        output = subprocess.check_output([
            "ios-sim", "--devicetypeid", self.device, "install", self.app_path, "--exit"
        ])

        log_info(output)
        list_output = subprocess.Popen(["xcrun", "simctl", "list"], stdout=subprocess.PIPE)
        output = subprocess.check_output(('grep', 'Booted'), stdin=list_output.stdout)
        if len(output.splitlines()) > 0:
            # Wait for the device to boot up
            # We check the status of the simulator using the command
            # xcrun simctl spawn booted launchctl print system | grep com.apple.springboard.services
            # If the simulator is still coming up, the output will say
            # 0x1d407    M   D   com.apple.springboard.services
            # If the simulator has booted up completely, it will say
            # 0x1e007    M   A   com.apple.springboard.services
            # We check if the third field is A
            start = time.time()
            while True:
                if time.time() - start > CLIENT_REQUEST_TIMEOUT:
                    raise LiteServError("iPhone Simulator failed to start")

                output = subprocess.Popen([
                    "xcrun", "simctl", "spawn", "booted", "launchctl", "print", "system"
                ], stdout=subprocess.PIPE)
                output = subprocess.check_output(('grep', 'com.apple.springboard.services'), stdin=output.stdout)
                output = re.sub(' +', ' ', output).strip()
                status = output.split(" ")[2]
                if status == "A":
                    log_info("iPhone Simulator seems to have booted up")
                    break
                else:
                    log_info("Waiting for the iPhone Simulator to boot up")
                    time.sleep(1)
                    continue

        # Get the device ID
        list_output = subprocess.Popen(["xcrun", "simctl", "list"], stdout=subprocess.PIPE)
        output = subprocess.check_output(('grep', 'Booted'), stdin=list_output.stdout)

        for line in output.splitlines():
            if "Phone" in line:
                self.device_id = re.sub(' +', ' ', line).strip()
                self.device_id = self.device_id.split(" ")[4]
                self.device_id = self.device_id.strip('(')
                self.device_id = self.device_id.strip(')')

        if not self.device_id:
            raise LiteServError("Could not get the device ID of the running simulator")
Exemplo n.º 11
0
 def remove(self):
     log_info("Removing windows server from: {}".format(self.host))
     status = self.ansible_runner.run_ansible_playbook(
         "remove-liteserv-msft.yml")
     if status != 0:
         raise LiteServError("Failed to install Liteserv on Windows host")