Ejemplo n.º 1
0
    def _make_tenant(self, plan, env):
        tname = "tenant-{}".format(plan)
        email = "user@{}.com".format(tname)

        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)

        env.new_tenant_client("test-container-{}".format(plan), ttoken)
        device = MenderDevice(env.get_mender_clients()[0])
        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 = device
        tenant.device_id = devices[0]
        tenant.auth = auth
        tenant.devauth = devauth

        return tenant
Ejemplo n.º 2
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