コード例 #1
0
def migrate_ent_setup(env):
    """ Migrate the ENT setup - create a tenant and user via create-org,
        substitute default token env in the ent. testing layer.
    """
    ensure_conductor_ready(env.get_mender_conductor(), 60, 'create_organization')

    # extra long sleep to make sure all services ran their migrations
    # maybe conductor fails because some services are still in a migration phase,
    # and not serving the API yet?
    time.sleep(30)

    u = User('', '*****@*****.**', 'correcthorse')

    cli = CliTenantadm(containers_namespace=env.name)
    tid = cli.create_org('tenant', u.name, u.pwd)
    time.sleep(10)

    tenant = cli.get_tenant(tid)

    tenant = json.loads(tenant)
    ttoken = tenant['tenant_token']

    t = Tenant('tenant', tid, ttoken)
    t.users.append(u)

    return {"tenant": t}
コード例 #2
0
def migrate_ent_setup():
    """ Migrate the ENT setup - create a tenant and user via create-org,
        substitute default token env in the ent. testing layer.
    """
    ensure_conductor_ready(60, 'create_organization')

    u = User('', '*****@*****.**', 'correcthorse')

    cli = CliTenantadm(docker_prefix=docker_compose_instance)
    tid = cli.create_org('tenant', u.name, u.pwd)
    time.sleep(10)

    tenant = cli.get_tenant(tid)

    tenant = json.loads(tenant)
    ttoken = tenant['tenant_token']

    sed = "sed 's/$DEFAULT_TENANT_TOKEN/{}/' ".format(ttoken) + \
          os.path.join(COMPOSE_FILES_PATH, "docker-compose.testing.enterprise.yml.template") + \
          " > " + \
          os.path.join(COMPOSE_FILES_PATH, "docker-compose.testing.enterprise.yml")

    subprocess.check_call(sed, shell=True)

    t = Tenant('tenant', tid, ttoken)
    t.users.append(u)

    return {"tenant": t}
コード例 #3
0
    def _make_tenant(self, plan, env):
        uuidv4 = str(uuid.uuid4())
        tname = "test.mender.io-{}-{}".format(uuidv4, plan)
        email = "some.user+{}@example.com".format(uuidv4)

        cli = CliTenantadm(containers_namespace=env.name)
        tid = cli.create_org(tname, email, "correcthorse", plan)

        tenant = cli.get_tenant(tid)
        tenant = json.loads(tenant)
        ttoken = tenant["tenant_token"]

        # the cli now sets all addons to 'enabled' -
        # disable them for initial 'all disabled' state
        update_tenant(
            tenant["id"], addons=[], container_manager=get_container_manager(),
        )

        auth = Authentication(name=tname, username=email, password="******")
        auth.create_org = False
        auth.reset_auth_token()
        devauth = DeviceAuthV2(auth)

        new_tenant_client(env, "mender-client-{}".format(plan), ttoken)
        devauth.accept_devices(1)

        devices = list(
            set([device["id"] for device in devauth.get_devices_status("accepted")])
        )
        assert 1 == len(devices)

        tenant = Tenant(tname, tid, ttoken)
        u = User("", email, "correcthorse")

        tenant.users.append(u)
        tenant.device_id = devices[0]
        tenant.auth = auth
        tenant.devauth = devauth

        return tenant
コード例 #4
0
    def test_configuration(self, enterprise_no_client):
        """Tests the deployment and reporting of the configuration

        The tests set the configuration of a device and verifies the new
        configuration is reported back to the back-end.
        """

        env = enterprise_no_client

        # Create an enterprise plan tenant
        u = User("", "*****@*****.**", "whatsupdoc")
        cli = CliTenantadm(containers_namespace=env.name)
        tid = cli.create_org("enterprise-tenant",
                             u.name,
                             u.pwd,
                             plan="enterprise")
        tenant = cli.get_tenant(tid)
        tenant = json.loads(tenant)
        ttoken = tenant["tenant_token"]
        logger.info(f"tenant json: {tenant}")
        tenant = Tenant("tenant", tid, ttoken)
        tenant.users.append(u)

        # And authorize the user to the tenant account
        auth = Authentication(name="enterprise-tenant",
                              username=u.name,
                              password=u.pwd)
        auth.create_org = False
        auth.reset_auth_token()
        devauth_tenant = DeviceAuthV2(auth)

        # Add a client to the tenant
        enterprise_no_client.new_tenant_client("configuration-test-container",
                                               tenant.tenant_token)
        mender_device = MenderDevice(
            enterprise_no_client.get_mender_clients()[0])
        mender_device.ssh_is_opened()

        devauth_tenant.accept_devices(1)

        # list of devices
        devices = list(
            set([
                device["id"]
                for device in devauth_tenant.get_devices_status("accepted")
            ]))
        assert 1 == len(devices)

        wait_for_connect(auth, devices[0])

        # set and verify the device's configuration
        # retry to skip possible race conditions between update poll and update trigger
        for _ in redo.retrier(attempts=3, sleeptime=1):
            set_and_verify_config({"key": "value"}, devices[0],
                                  auth.get_auth_token())

            forced = was_update_forced(mender_device)
            if forced:
                return

        assert False, "the update check was never triggered"
コード例 #5
0
    def test_deployment_retry_failed_update(self, enterprise_no_client):
        """Tests that a client installing a deployment created with a retry limit

        This is done through setting up a new tenant on the enterprise plan,
        with a device bootstrapped to the tenant. Then an Artifact is created
        which contains a script, for the script update module. The script will
        store a retry-count in a temp-file on the device, and fail, as long as
        the retry-count < 3. On the third go, the script will, pass, and along
        with it, so should the update.

        """

        env = enterprise_no_client

        # Create an enterprise plan tenant
        u = User("", "*****@*****.**", "whatsupdoc")
        cli = CliTenantadm(containers_namespace=env.name)
        tid = cli.create_org("enterprise-tenant",
                             u.name,
                             u.pwd,
                             plan="enterprise")
        tenant = cli.get_tenant(tid)
        tenant = json.loads(tenant)
        ttoken = tenant["tenant_token"]
        logger.info(f"tenant json: {tenant}")
        tenant = Tenant("tenant", tid, ttoken)
        tenant.users.append(u)

        # And authorize the user to the tenant account
        auth = Authentication(name="enterprise-tenant",
                              username=u.name,
                              password=u.pwd)
        auth.create_org = False
        auth.reset_auth_token()
        devauth = DeviceAuthV2(auth)
        deploy = Deployments(auth, devauth)

        # Add a client to the tenant
        enterprise_no_client.new_tenant_client("retry-test-container",
                                               tenant.tenant_token)
        devauth.accept_devices(1)
        device = MenderDevice(env.get_mender_clients()[0])

        with tempfile.NamedTemporaryFile() as tf:

            artifact = make_script_artifact("retry-artifact",
                                            conftest.machine_name, tf.name)

            deploy.upload_image(artifact)

            devices = list(
                set([
                    device["id"]
                    for device in devauth.get_devices_status("accepted")
                ]))
            assert len(devices) == 1

            deployment_id = deploy.trigger_deployment(
                "retry-test",
                artifact_name="retry-artifact",
                devices=devices,
                retries=3)
            logger.info(deploy.get_deployment(deployment_id))

            # Now just wait for the update to succeed
            deploy.check_expected_statistics(deployment_id, "success", 1)
            deploy.check_expected_status("finished", deployment_id)

            # Verify the update was actually installed on the device
            out = device.run("mender -show-artifact").strip()
            assert out == "retry-artifact"

            # Verify the number of attempts taken to install the update
            out = device.run("cat /tmp/retry-attempts").strip()
            assert out == "3"
コード例 #6
0
    def test_configuration(self, enterprise_no_client):
        """Tests the deployment and reporting of the configuration

        The tests set the configuration of a device and verifies the new
        configuration is reported back to the back-end.
        """

        env = enterprise_no_client

        # Create an enterprise plan tenant
        uuidv4 = str(uuid.uuid4())
        tname = "test.mender.io-{}".format(uuidv4)
        email = "some.user+{}@example.com".format(uuidv4)
        u = User("", email, "whatsupdoc")
        cli = CliTenantadm(containers_namespace=env.name)
        tid = cli.create_org(tname, u.name, u.pwd, plan="enterprise")

        # what we really need is "configure"
        # but for trigger tests we're also checking device avail. in "deviceconnect"
        # so add "troubleshoot" as well
        update_tenant(
            tid,
            addons=["configure", "troubleshoot"],
            container_manager=get_container_manager(),
        )

        tenant = cli.get_tenant(tid)
        tenant = json.loads(tenant)
        ttoken = tenant["tenant_token"]
        logger.info(f"tenant json: {tenant}")
        tenant = Tenant("tenant", tid, ttoken)
        tenant.users.append(u)

        # And authorize the user to the tenant account
        auth = Authentication(name="enterprise-tenant",
                              username=u.name,
                              password=u.pwd)
        auth.create_org = False
        auth.reset_auth_token()
        devauth_tenant = DeviceAuthV2(auth)

        # Add a client to the tenant
        mender_device = new_tenant_client(enterprise_no_client,
                                          "mender-client", tenant.tenant_token)
        mender_device.ssh_is_opened()

        devauth_tenant.accept_devices(1)

        # list of devices
        devices = list(
            set([
                device["id"]
                for device in devauth_tenant.get_devices_status("accepted")
            ]))
        assert 1 == len(devices)

        wait_for_connect(auth, devices[0])

        # set and verify the device's configuration
        # retry to skip possible race conditions between update poll and update trigger
        for _ in redo.retrier(attempts=3, sleeptime=1):
            set_and_verify_config({"key": "value"}, devices[0],
                                  auth.get_auth_token())

            forced = was_update_forced(mender_device)
            if forced:
                return

        assert False, "the update check was never triggered"
コード例 #7
0
    def _make_trial_tenant(self, env):
        uuidv4 = str(uuid.uuid4())
        tname = "test.mender.io-{}-{}".format(uuidv4, "trial")
        email = "some.user+{}@example.com".format(uuidv4)

        tadmm = ApiClient(
            host=get_container_manager().get_mender_gateway(),
            base_url=tenantadm_v2.URL_MGMT,
        )

        args = {
            "organization": tname,
            "email": email,
            "password": "******",
            "name": "foo",
            "g-recaptcha-response": "dummy",
            "plan": "enterprise",
        }

        res = tadmm.call("POST", tenantadm_v2.URL_CREATE_ORG_TRIAL, body=args,)

        assert res.status_code == 202

        # get tenant id
        tenantadm_host = (
            tenantadm.HOST
            if isK8S()
            else get_container_manager().get_ip_of_service("mender-tenantadm")[0]
            + ":8080"
        )
        tadmi = ApiClient(
            host=tenantadm_host, base_url=tenantadm.URL_INTERNAL, schema="http://",
        )

        res = tadmi.call(
            "GET", tenantadm.URL_INTERNAL_TENANTS, qs_params={"username": email}
        )
        assert res.status_code == 200
        assert len(res.json()) == 1

        apitenant = res.json()[0]

        cli = CliTenantadm(containers_namespace=env.name)

        tenant = cli.get_tenant(apitenant["id"])
        tenant = json.loads(tenant)
        ttoken = tenant["tenant_token"]

        auth = Authentication(name=tname, username=email, password="******")
        auth.create_org = False
        auth.reset_auth_token()
        devauth = DeviceAuthV2(auth)

        new_tenant_client(env, "mender-client-trial", ttoken)
        devauth.accept_devices(1)

        devices = list(
            set([device["id"] for device in devauth.get_devices_status("accepted")])
        )
        assert 1 == len(devices)

        tenant = Tenant(tname, apitenant["id"], ttoken)
        u = User("", email, "correcthorse")

        tenant.users.append(u)
        tenant.device_id = devices[0]
        tenant.auth = auth
        tenant.devauth = devauth

        return tenant