Пример #1
0
    def test_send_signup_confirmation_factory_exception(self):
        stdout = StringIO()
        stderr = StringIO()

        def call_ESMTPSenderFactory(username,
                                    password,
                                    fromEmail,
                                    toEmail,
                                    f,
                                    d,
                                    retries=5,
                                    timeout=None,
                                    contextFactory=None,
                                    heloFallback=False,
                                    requireAuthentication=True,
                                    requireTransportSecurity=True):
            raise MarkerException()

        self.patch(send_email, 'ESMTPSenderFactory', call_ESMTPSenderFactory)

        d = send_signup_confirmation(self.PUBIP, self.CUSTOMER_NAME,
                                     self.CUSTOMER_EMAIL,
                                     self.EXTERNAL_INTRODUCER_FURL, '', stdout,
                                     stderr)

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

        def _check_failure(f):
            f.trap(MarkerException)
            out = stdout.getvalue()
            self.failUnlessIn("Sending of e-mail failed", out)

        d.addCallbacks(_bad_success, _check_failure)
        return d
Пример #2
0
            def _got_sshfp(ignored):
                retries = LISTEN_RETRIES
                while True:
                    try:
                        install_server(publichost, admin_privkey_path, monitor_pubkey,
                                       monitor_privkey_path, stdout, stderr)
                        break
                    except NotListeningError:
                        retries -= 1
                        if retries <= 0:
                            print >>stdout, "Timed out waiting for EC2 instance to listen for ssh connections."
                            raise TimeoutError()
                        print >>stdout, "Waiting another %d seconds..." % (LISTEN_POLL_TIME)
                        time.sleep(LISTEN_POLL_TIME)
                        continue

                furl = bounce_server(publichost, admin_privkey_path, privatehost, useraccesskeyid,
                                     usersecretkey, usertoken, producttoken, bucketname, oldsecrets,
                                     stdout, stderr, secretsfile)

                # XXX We'll have to ammend this:
                initialize_statmover_source(publichost, monitor_privkey_path, admin_privkey_path,
                                            sinkname_suffix, [instance.instance_id, 'SSEC2s'])
                # XXX We probably need to rethink this:
                append_record(FilePath(serverinfopath), instance.launch_time, instance.instance_id,
                              publichost)

                print >>stderr, "Signup done."
                d4 = defer.succeed(None)
                if not oldsecrets:
                    d4.addCallback(lambda ign: send_signup_confirmation(publichost, customer_name,
                                                                        customer_email, furl,
                                                                        customer_keyinfo,
                                                                        stdout, stderr) )
                return d4
Пример #3
0
    def _test_send_signup_confirmation_success(self, call_factory,
                                               customer_keyinfo):
        self.the_factory = Mock()
        self.patch(send_email, 'ESMTPSenderFactory', call_factory)

        connected = {}

        def call_connectTCP(smtphost, port, factory):
            self.failUnlessEqual(smtphost, self.SMTP_HOST)
            self.failUnlessEqual(port, self.SMTP_PORT)
            self.failUnlessEqual(factory, self.the_factory)
            self.failUnlessEqual(factory.domain, self.SENDER_DOMAIN)
            connected['flag'] = True

        self.patch(send_email, 'connectTCP', call_connectTCP)

        stdout = StringIO()
        stderr = StringIO()
        d = send_signup_confirmation(self.PUBIP, self.CUSTOMER_NAME,
                                     self.CUSTOMER_EMAIL,
                                     self.EXTERNAL_INTRODUCER_FURL,
                                     customer_keyinfo, stdout, stderr)

        def _check(ign):
            self.failUnless('flag' in connected)
            out = stdout.getvalue()
            self.failUnlessIn("confirmation e-mail", out)
            self.failUnlessIn(self.CUSTOMER_EMAIL, out)
            self.failUnlessIn("sent.", out)

        d.addCallback(_check)
        return d
    def _test_send_signup_confirmation_success(self, call_factory, customer_keyinfo):
        self.the_factory = Mock()
        self.patch(send_email, 'ESMTPSenderFactory', call_factory)

        connected = {}
        def call_connectTCP(smtphost, port, factory):
            self.failUnlessEqual(smtphost, self.SMTP_HOST)
            self.failUnlessEqual(port, self.SMTP_PORT)
            self.failUnlessEqual(factory, self.the_factory)
            self.failUnlessEqual(factory.domain, self.SENDER_DOMAIN)
            connected['flag'] = True
        self.patch(send_email, 'connectTCP', call_connectTCP)

        stdout = StringIO()
        stderr = StringIO()
        d = send_signup_confirmation(self.PUBIP, self.CUSTOMER_NAME, self.CUSTOMER_EMAIL, self.EXTERNAL_INTRODUCER_FURL,
                                     customer_keyinfo, stdout, stderr)
        def _check(ign):
            self.failUnless('flag' in connected)
            out = stdout.getvalue()
            self.failUnlessIn("confirmation e-mail", out)
            self.failUnlessIn(self.CUSTOMER_EMAIL, out)
            self.failUnlessIn("sent.", out)
        d.addCallback(_check)
        return d
    def test_send_signup_confirmation_connect_exception(self):
        stdout = StringIO()
        stderr = StringIO()

        def call_ESMTPSenderFactory(username, password, fromEmail, toEmail, f, d,
                                    retries=5, timeout=None, contextFactory=None, heloFallback=False,
                                    requireAuthentication=True, requireTransportSecurity=True):
            eventually(d.callback, None)
            return Mock()
        self.patch(send_email, 'ESMTPSenderFactory', call_ESMTPSenderFactory)

        def call_connectTCP(smtphost, port, factory):
            raise MarkerException()
        self.patch(send_email, 'connectTCP', call_connectTCP)

        d = send_signup_confirmation(self.PUBIP, self.CUSTOMER_NAME, self.CUSTOMER_EMAIL, self.EXTERNAL_INTRODUCER_FURL,
                                     '', stdout, stderr)
        def _bad_success(ign):
            self.fail("should have got a failure")
        def _check_failure(f):
            f.trap(MarkerException)
            out = stdout.getvalue()
            self.failUnlessIn("Sending of e-mail failed", out)
        d.addCallbacks(_bad_success, _check_failure)
        return d
Пример #6
0
            def _got_sshfp(ignored):
                retries = LISTEN_RETRIES
                while True:
                    try:
                        install_server(publichost, admin_privkey_path, monitor_pubkey,
                                       monitor_privkey_path, stdout, stderr)
                        break
                    except NotListeningError:
                        retries -= 1
                        if retries <= 0:
                            print >>stdout, "Timed out waiting for EC2 instance to listen for ssh connections."
                            raise TimeoutError()
                        print >>stdout, "Waiting another %d seconds..." % (LISTEN_POLL_TIME)
                        time.sleep(LISTEN_POLL_TIME)
                        continue

                furl = bounce_server(publichost, admin_privkey_path, privatehost, useraccesskeyid,
                                     usersecretkey, usertoken, producttoken, bucketname, oldsecrets,
                                     stdout, stderr, secretsfile)

                # Disabled for now.
                #initialize_statmover_source(publichost, monitor_privkey_path, admin_privkey_path,
                #                            sinkname_suffix, [instance.instance_id, 'SSEC2s'])

                # XXX We probably need to rethink this:
                append_record(FilePath(serverinfopath), instance.launch_time, instance.instance_id,
                              publichost)

                print >>stderr, "Signup done."
                d4 = defer.succeed(None)
                if not oldsecrets:
                    d4.addCallback(lambda ign: send_signup_confirmation(publichost, customer_name,
                                                                        customer_email, furl,
                                                                        customer_keyinfo,
                                                                        stdout, stderr) )
                return d4
Пример #7
0
from twisted.internet import reactor
from twisted.python.failure import Failure

from lae_automation.confirmation import send_signup_confirmation


if len(sys.argv) < 4:
    print "Usage: python confirm.py CUSTOMER_NAME CUSTOMER_EMAIL INTRODUCER_FURL [CUSTOMER_KEYINFO]"
    print "Happy confirmation-sending!"
    sys.exit(1)

customer_name = sys.argv[1]
customer_email = sys.argv[2]
external_introducer_furl = sys.argv[3]
if len(sys.argv) > 4:
    customer_keyinfo = sys.argv[4]
else:
    customer_keyinfo = ''

def cb(x):
    print str(x)
    if isinstance(x, Failure) and hasattr(x.value, 'response'):
        print x.value.response

d = send_signup_confirmation(customer_name, customer_email, external_introducer_furl, customer_keyinfo,
                             sys.stdout, sys.stderr)
d.addBoth(cb)
d.addCallbacks(lambda ign: os._exit(0), lambda ign: os._exit(1))
reactor.run()