def test_EC2_not_listening(self):
        MACTIVATIONKEY = 'MOCKACTIVATONKEY'
        MPRODUCTCODE = 'ABCDEFGH'
        MNAME = 'MNAME'
        MEMAIL = 'MEMAIL'
        MKEYINFO = 'MKEYINFO'
        stdout = StringIO()
        stderr = StringIO()
        MSEED = 'MSEED'
        MSECRETSFILE = 'MSECRETSFILE'
        MLOGFILENAME = '2012-01-01T000000Z-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        self.patch(signup, 'VERIFY_POLL_TIME', .1)
        self.patch(signup, 'VERIFY_TOTAL_WAIT', .2)

        from lae_automation.aws import queryapi
        def call_get_EC2_consoleoutput(ec2accesskeyid, ec2secretkey, endpoint_uri, instance_id):
            return defer.succeed(None)
        self.patch(queryapi, 'get_EC2_consoleoutput', call_get_EC2_consoleoutput)

        d = signup.signup(MACTIVATIONKEY, MPRODUCTCODE, MNAME, MEMAIL, MKEYINFO, stdout, stderr,
                          MSEED, MSECRETSFILE, MLOGFILENAME, self.CONFIGFILEPATH,
                          self.SERVERINFOPATH, self.EC2SECRETPATH)
        def _bad_success(ign):
            self.fail("should have got a failure")
        def _check_failure(f):
            f.trap(signup.TimeoutError)
            out = stdout.getvalue()
            self.failUnlessIn("Timed out", out)
        d.addCallbacks(_bad_success, _check_failure)
        return d
    def test_timeout_verify(self):
        MACTIVATIONKEY = 'MOCKACTIVATONKEY'
        MPRODUCTCODE = 'ABCDEFGH'
        MNAME = 'MNAME'
        MEMAIL = 'MEMAIL'
        MKEYINFO = 'MKEYINFO'
        stdout = StringIO()
        stderr = StringIO()
        MSEED = 'MSEED'
        MSECRETSFILE = 'MSECRETSFILE'
        MLOGFILENAME = '2012-01-01T000000Z-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

        def call_verify_user_account(useraccesskeyid, usersecretkey, usertoken, producttoken, stdout,
                                     stderr):
            return defer.succeed(False)
        self.patch(signup, 'verify_user_account', call_verify_user_account)

        d = signup.signup(MACTIVATIONKEY, MPRODUCTCODE, MNAME, MEMAIL, MKEYINFO, stdout, stderr,
                          MSEED, MSECRETSFILE, MLOGFILENAME, self.CONFIGFILEPATH,
                          self.SERVERINFOPATH, self.EC2SECRETPATH)
        def _bad_success(ign):
            self.fail("should have got a failure")
        def _check_failure(f):
            f.trap(signup.TimeoutError)
            out = stdout.getvalue()
            self.failUnlessIn("Timed out", out)
        d.addCallbacks(_bad_success, _check_failure)
        return d
    def test_timeout_addressreq(self):
        MACTIVATIONKEY = 'MOCKACTIVATONKEY'
        MPRODUCTCODE = 'ABCDEFGH'
        MNAME = 'MNAME'
        MEMAIL = 'MEMAIL'
        MKEYINFO = 'MKEYINFO'
        stdout = StringIO()
        stderr = StringIO()
        MSEED = 'MSEED'
        MSECRETSFILE = 'MSECRETSFILE'
        MLOGFILENAME = '2012-01-01T000000Z-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

        from lae_automation.aws import queryapi
        def call_get_EC2_properties(ec2accesskeyid, ec2secretkey, EC2_ENDPOINT, parser,
                                    *instance_ids):
            return defer.succeed(None)
        self.patch(queryapi, 'get_EC2_properties', call_get_EC2_properties)

        d = signup.signup(MACTIVATIONKEY, MPRODUCTCODE, MNAME, MEMAIL, MKEYINFO, stdout, stderr,
                          MSEED, MSECRETSFILE, MLOGFILENAME, self.CONFIGFILEPATH,
                          self.SERVERINFOPATH, self.EC2SECRETPATH)
        def _bad_success(ign):
            self.fail("should have got a failure")
        def _check_failure(f):
            f.trap(signup.TimeoutError)
            out = stdout.getvalue()
            self.failUnlessIn("Timed out", out)
        d.addCallbacks(_bad_success, _check_failure)
        return d
    def test_timeout_addressreq(self):
        MACTIVATIONKEY = 'MOCKACTIVATONKEY'
        MPRODUCTCODE = 'ABCDEFGH'
        MNAME = 'MNAME'
        MEMAIL = 'MEMAIL'
        MKEYINFO = 'MKEYINFO'
        stdout = StringIO()
        stderr = StringIO()
        MSEED = 'MSEED'
        MSECRETSFILE = 'MSECRETSFILE'
        MLOGFILENAME = '2012-01-01T000000Z-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

        from lae_automation.aws import queryapi

        def call_get_EC2_properties(ec2accesskeyid, ec2secretkey, EC2_ENDPOINT,
                                    parser, *instance_ids):
            return defer.succeed(None)

        self.patch(queryapi, 'get_EC2_properties', call_get_EC2_properties)

        d = signup.signup(MACTIVATIONKEY, MPRODUCTCODE, MNAME, MEMAIL,
                          MKEYINFO, stdout, stderr, MSEED, MSECRETSFILE,
                          MLOGFILENAME, self.CONFIGFILEPATH,
                          self.SERVERINFOPATH, self.EC2SECRETPATH)

        def _bad_success(ign):
            self.fail("should have got a failure")

        def _check_failure(f):
            f.trap(signup.TimeoutError)
            out = stdout.getvalue()
            self.failUnlessIn("Timed out", out)

        d.addCallbacks(_bad_success, _check_failure)
        return d
    def test_signup(self):
        MACTIVATIONKEY = 'MOCKACTIVATONKEY'
        MPRODUCTCODE = 'ABCDEFGH'
        MNAME = 'MNAME'
        MEMAIL = 'MEMAIL'
        MKEYINFO = 'MKEYINFO'
        stdout = StringIO()
        stderr = StringIO()
        MSEED = 'MSEED'
        MSECRETSFILE = 'MSECRETSFILE'
        MLOGFILENAME = '2012-01-01T000000Z-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        self.patch(signup, 'VERIFY_POLL_TIME', .1)
        self.patch(signup, 'VERIFY_TOTAL_WAIT', .2)

        def call_initialize_statmover_source(publichost, monitor_privkey_path, admin_privkey_path, suffixname, COLLECTIONNAMES):
            self.failUnlessEqual(publichost, '0.0.0.0')
            self.failUnlessEqual(monitor_privkey_path, 'MONITORKEYS.pem')
            self.failUnlessEqual(admin_privkey_path, 'ADMINKEYS.pem')
            self.failUnlessEqual(COLLECTIONNAMES[0], 'i-MOCKEC2INSTANCEID')
            self.failUnlessEqual(COLLECTIONNAMES[1], 'SSEC2s')
            self.failUnlessEqual(suffixname, 'unitteststorageserver/rss')
        #self.patch(signup, 'initialize_statmover_source', call_initialize_statmover_source)

        from lae_automation.aws import queryapi
        def call_hostpubkeyextractor(consoletext, instanceId):
            return MOCKSERVERSSHFP
        self.patch(queryapi, 'hostpubkeyextractor', call_hostpubkeyextractor)

        d = signup.signup(MACTIVATIONKEY, MPRODUCTCODE, MNAME, MEMAIL, MKEYINFO, stdout, stderr,
                          MSEED, MSECRETSFILE, MLOGFILENAME, self.CONFIGFILEPATH,
                          self.SERVERINFOPATH, self.EC2SECRETPATH)
        return d
    def test_timeout_verify(self):
        MACTIVATIONKEY = 'MOCKACTIVATONKEY'
        MPRODUCTCODE = 'ABCDEFGH'
        MNAME = 'MNAME'
        MEMAIL = 'MEMAIL'
        MKEYINFO = 'MKEYINFO'
        stdout = StringIO()
        stderr = StringIO()
        MSEED = 'MSEED'
        MSECRETSFILE = 'MSECRETSFILE'
        MLOGFILENAME = '2012-01-01T000000Z-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

        def call_verify_user_account(useraccesskeyid, usersecretkey, usertoken,
                                     producttoken, stdout, stderr):
            return defer.succeed(False)

        self.patch(signup, 'verify_user_account', call_verify_user_account)

        d = signup.signup(MACTIVATIONKEY, MPRODUCTCODE, MNAME, MEMAIL,
                          MKEYINFO, stdout, stderr, MSEED, MSECRETSFILE,
                          MLOGFILENAME, self.CONFIGFILEPATH,
                          self.SERVERINFOPATH, self.EC2SECRETPATH)

        def _bad_success(ign):
            self.fail("should have got a failure")

        def _check_failure(f):
            f.trap(signup.TimeoutError)
            out = stdout.getvalue()
            self.failUnlessIn("Timed out", out)

        d.addCallbacks(_bad_success, _check_failure)
        return d
def main(stdin, stdout, stderr, seed, secretsfile, logfilename):
    print >>stdout, "Automation script started."
    print >>stderr, "On separate lines: Activation key, Product code, Name, Email, Key info"
    activationkey = stdin.readline().strip()
    productcode = stdin.readline().strip()
    name = stdin.readline().strip()
    email = stdin.readline().strip()
    keyinfo = stdin.readline().strip()

    if keyinfo is None:
        # EOF reached before 5 lines (including blank lines) were input
        raise AssertionError("full_signup.py: some information was not received. Please report this to <*****@*****.**>.")

    print >>stderr, "Received all fields, thanks."
    try:
        from lae_automation.signup import signup
        return signup(activationkey, productcode, name, email, keyinfo, stdout, stderr, seed, secretsfile, logfilename)
    except Exception:
        import traceback
        traceback.print_exc(100, stdout)
        raise
def main(stdin, stdout, stderr, seed, secretsfile, logfilename):
    print >>stdout, "Automation script started."
    print >>stderr, "On separate lines: Activation key, Product code, Name, Email, Key info"
    activationkey = stdin.readline().strip()
    productcode = stdin.readline().strip()
    name = stdin.readline().strip()
    email = stdin.readline().strip()
    keyinfo = stdin.readline().strip()

    if keyinfo is None:
        # EOF reached before 5 lines (including blank lines) were input
        raise AssertionError("full_signup.py: some information was not received. Please report this to <*****@*****.**>.")

    print >>stderr, "Received all fields, thanks."
    try:
        from lae_automation.signup import signup
        return signup(activationkey, productcode, name, email, keyinfo, stdout, stderr, seed, secretsfile, logfilename)
    except Exception:
        import traceback
        traceback.print_exc(100, stdout)
        raise
    def test_EC2_not_listening(self):
        MACTIVATIONKEY = 'MOCKACTIVATONKEY'
        MPRODUCTCODE = 'ABCDEFGH'
        MNAME = 'MNAME'
        MEMAIL = 'MEMAIL'
        MKEYINFO = 'MKEYINFO'
        stdout = StringIO()
        stderr = StringIO()
        MSEED = 'MSEED'
        MSECRETSFILE = 'MSECRETSFILE'
        MLOGFILENAME = '2012-01-01T000000Z-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        self.patch(signup, 'VERIFY_POLL_TIME', .1)
        self.patch(signup, 'VERIFY_TOTAL_WAIT', .2)

        from lae_automation.aws import queryapi

        def call_get_EC2_consoleoutput(ec2accesskeyid, ec2secretkey,
                                       endpoint_uri, instance_id):
            return defer.succeed(None)

        self.patch(queryapi, 'get_EC2_consoleoutput',
                   call_get_EC2_consoleoutput)

        d = signup.signup(MACTIVATIONKEY, MPRODUCTCODE, MNAME, MEMAIL,
                          MKEYINFO, stdout, stderr, MSEED, MSECRETSFILE,
                          MLOGFILENAME, self.CONFIGFILEPATH,
                          self.SERVERINFOPATH, self.EC2SECRETPATH)

        def _bad_success(ign):
            self.fail("should have got a failure")

        def _check_failure(f):
            f.trap(signup.TimeoutError)
            out = stdout.getvalue()
            self.failUnlessIn("Timed out", out)

        d.addCallbacks(_bad_success, _check_failure)
        return d
    def test_signup(self):
        MACTIVATIONKEY = 'MOCKACTIVATONKEY'
        MPRODUCTCODE = 'ABCDEFGH'
        MNAME = 'MNAME'
        MEMAIL = 'MEMAIL'
        MKEYINFO = 'MKEYINFO'
        stdout = StringIO()
        stderr = StringIO()
        MSEED = 'MSEED'
        MSECRETSFILE = 'MSECRETSFILE'
        MLOGFILENAME = '2012-01-01T000000Z-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        self.patch(signup, 'VERIFY_POLL_TIME', .1)
        self.patch(signup, 'VERIFY_TOTAL_WAIT', .2)

        def call_initialize_statmover_source(publichost, monitor_privkey_path,
                                             admin_privkey_path, suffixname,
                                             COLLECTIONNAMES):
            self.failUnlessEqual(publichost, '0.0.0.0')
            self.failUnlessEqual(monitor_privkey_path, 'MONITORKEYS.pem')
            self.failUnlessEqual(admin_privkey_path, 'ADMINKEYS.pem')
            self.failUnlessEqual(COLLECTIONNAMES[0], 'i-MOCKEC2INSTANCEID')
            self.failUnlessEqual(COLLECTIONNAMES[1], 'SSEC2s')
            self.failUnlessEqual(suffixname, 'unitteststorageserver/rss')

        #self.patch(signup, 'initialize_statmover_source', call_initialize_statmover_source)

        from lae_automation.aws import queryapi

        def call_hostpubkeyextractor(consoletext, instanceId):
            return MOCKSERVERSSHFP

        self.patch(queryapi, 'hostpubkeyextractor', call_hostpubkeyextractor)

        d = signup.signup(MACTIVATIONKEY, MPRODUCTCODE, MNAME, MEMAIL,
                          MKEYINFO, stdout, stderr, MSEED, MSECRETSFILE,
                          MLOGFILENAME, self.CONFIGFILEPATH,
                          self.SERVERINFOPATH, self.EC2SECRETPATH)
        return d
 def _make_wormhole_claim(self, customer_email, customer_id, subscription_id, old_secrets):
     plan_identifier = u"foobar"
     reactor = Clock()
     provisioner = get_provisioner(
         reactor,
         URL.fromText(u"http://subscription-manager/"),
         partial(self._provision_subscription, old_secrets),
     )
     server = MemoryWormholeServer()
     signup = get_wormhole_signup(
         reactor,
         provisioner,
         server,
         URL.fromText(u"ws://foo.invalid/"),
         FilePath(self.mktemp()),
     )
     d = signup.signup(
         customer_email,
         customer_id,
         subscription_id,
         plan_identifier,
     )
     return self.successResultOf(d)
Exemple #12
0
    def test_emailed_introducer_furl(
            self,
            customer_email,
            customer_id,
            subscription_id,
            old_secrets,
            introducer_port_number,
            storage_port_number,
    ):
        """
        The email signup mechanism sends an activation email including an
        introducer furl which points at the server and port identified by the
        activated subscription detail object.
        """
        assume(introducer_port_number != storage_port_number)

        emails = []

        def provision_subscription(
                smclient, subscription,
        ):
            return succeed(
                attr.assoc(
                    subscription,
                    introducer_port_number=introducer_port_number,
                    storage_port_number=storage_port_number,
                    oldsecrets=old_secrets,
                ),
            )

        def send_signup_confirmation(
                customer_email, external_introducer_furl, customer_keyinfo, stdout, stderr,
        ):
            emails.append((customer_email, "success", external_introducer_furl))
            return succeed(None)

        def send_notify_failure(
                reason, customer_email, logfilename, stdout, stderr,
        ):
            emails.append((customer_email, "failure", reason))
            return succeed(None)

        plan_identifier = u"foobar"

        reactor = object()
        signup = get_email_signup(
            reactor,
            get_provisioner(
                reactor,
                URL.fromText(u"http://subscription-manager/"),
                provision_subscription,
            ),
            send_signup_confirmation,
            send_notify_failure,
        )
        d = signup.signup(customer_email, customer_id, subscription_id, plan_identifier)
        self.successResultOf(d)

        [(recipient, result, rest)] = emails
        self.expectThat(recipient, Equals(customer_email))
        self.expectThat(result, Equals("success"))

        def get_hint_port(furl):
            tub_id, location_hints, name = decode_furl(furl)
            host, port = location_hints[0].split(u":")
            return int(port)

        self.expectThat(
            rest,
            AfterPreprocessing(
                get_hint_port,
                Equals(introducer_port_number),
            ),
        )
Exemple #13
0
    def test_wormhole_tahoe_configuration(
            self,
            customer_email,
            customer_id,
            subscription_id,
            old_secrets,
            introducer_port_number,
            storage_port_number,
    ):
        """
        The wormhole signup mechanism sends a JSON blob of Tahoe-LAFS
        configuration via a magic wormhole identified by a wormhole code
        produced during signup.
        """
        assume(introducer_port_number != storage_port_number)

        provisioned = []
        def provision_subscription(
                smclient, subscription,
        ):
            p = attr.assoc(
                subscription,
                introducer_port_number=introducer_port_number,
                storage_port_number=storage_port_number,
                oldsecrets=old_secrets,
            )
            provisioned.append(p)
            return succeed(p)

        plan_identifier = u"foobar"
        reactor = Clock()
        server = MemoryWormholeServer()

        provisioner = get_provisioner(
            reactor,
            URL.fromText(u"http://subscription-manager/"),
            provision_subscription,
        )

        signup = get_wormhole_signup(
            reactor,
            provisioner,
            server,
            URL.fromText(u"ws://foo.invalid/"),
            FilePath(self.mktemp()),
        )
        d = signup.signup(customer_email, customer_id, subscription_id, plan_identifier)
        wormhole_claim = self.successResultOf(d)

        wh = server.create(
            u"tahoe-lafs.org/tahoe-lafs/v1",
            u"ws://foo.invalid/",
            reactor,
        )

        wh.set_code(wormhole_claim.code)
        d = wh.when_code()

        def foo(x):
            wh.send_message('{"abilities": {"client-v1": {}}}')
            return wh.get_message()
        d.addCallback(foo)

        def bar(arg):
            self.assertEqual(
                loads(arg),
                {"abilities": {"server-v1":{}}}
            )
            return wh.get_message()
        d.addCallback(bar)

        received = self.successResultOf(d)
        received_config = loads(received)
        self.assertThat(
            received_config["introducer"],
            Equals(provisioned[0].external_introducer_furl),
        )
    def test_emailed_introducer_furl(
            self,
            customer_email,
            customer_id,
            subscription_id,
            old_secrets,
            introducer_port_number,
            storage_port_number,
    ):
        """
        The email signup mechanism sends an activation email including an
        introducer furl which points at the server and port identified by the
        activated subscription detail object.
        """
        assume(introducer_port_number != storage_port_number)

        emails = []

        def provision_subscription(
                smclient, subscription,
        ):
            return succeed(
                attr.assoc(
                    subscription,
                    introducer_port_number=introducer_port_number,
                    storage_port_number=storage_port_number,
                    oldsecrets=old_secrets,
                ),
            )

        def send_signup_confirmation(
                customer_email, external_introducer_furl, customer_keyinfo, stdout, stderr,
        ):
            emails.append((customer_email, "success", external_introducer_furl))
            return succeed(None)

        def send_notify_failure(
                reason, customer_email, logfilename, stdout, stderr,
        ):
            emails.append((customer_email, "failure", reason))
            return succeed(None)

        plan_identifier = u"foobar"

        reactor = object()
        signup = get_email_signup(
            reactor,
            get_provisioner(
                reactor,
                URL.fromText(u"http://subscription-manager/"),
                provision_subscription,
            ),
            send_signup_confirmation,
            send_notify_failure,
        )
        d = signup.signup(customer_email, customer_id, subscription_id, plan_identifier)
        self.successResultOf(d)

        [(recipient, result, rest)] = emails
        self.expectThat(recipient, Equals(customer_email))
        self.expectThat(result, Equals("success"))

        def get_hint_port(furl):
            tub_id, location_hints, name = decode_furl(furl)
            host, port = location_hints[0].split(u":")
            return int(port)

        self.expectThat(
            rest,
            AfterPreprocessing(
                get_hint_port,
                Equals(introducer_port_number),
            ),
        )
    def test_wormhole_tahoe_configuration(
            self,
            customer_email,
            customer_id,
            subscription_id,
            old_secrets,
            introducer_port_number,
            storage_port_number,
    ):
        """
        The wormhole signup mechanism sends a JSON blob of Tahoe-LAFS
        configuration via a magic wormhole identified by a wormhole code
        produced during signup.
        """
        assume(introducer_port_number != storage_port_number)

        provisioned = []
        def provision_subscription(
                smclient, subscription,
        ):
            p = attr.assoc(
                subscription,
                introducer_port_number=introducer_port_number,
                storage_port_number=storage_port_number,
                oldsecrets=old_secrets,
            )
            provisioned.append(p)
            return succeed(p)

        plan_identifier = u"foobar"
        reactor = Clock()
        server = MemoryWormholeServer()

        provisioner = get_provisioner(
            reactor,
            URL.fromText(u"http://subscription-manager/"),
            provision_subscription,
        )

        signup = get_wormhole_signup(
            reactor,
            provisioner,
            server,
            URL.fromText(u"ws://foo.invalid/"),
            FilePath(self.mktemp()),
        )
        d = signup.signup(customer_email, customer_id, subscription_id, plan_identifier)
        wormhole_claim = self.successResultOf(d)

        wh = server.create(
            APPID,
            u"ws://foo.invalid/",
            reactor,
        )

        wh.set_code(wormhole_claim.code)
        d = wh.when_code()

        def foo(x):
            wh.send_message('{"abilities": {"client-v1": {}}}')
            return wh.get_message()
        d.addCallback(foo)

        def bar(arg):
            self.assertEqual(
                loads(arg),
                {"abilities": {"server-v1":{}}}
            )
            return wh.get_message()
        d.addCallback(bar)

        received = self.successResultOf(d)
        received_config = loads(received)
        self.assertThat(
            received_config["introducer"],
            Equals(provisioned[0].external_introducer_furl),
        )