Пример #1
0
 def __init__(self):
     self.conductor_api = mox.MockAnything()
     self.db = mox.MockAnything()
     self._events = []
     self.instance_events = mock.MagicMock()
     self.instance_events.prepare_for_instance_event.side_effect = \
         self._prepare_for_instance_event
Пример #2
0
    def test_sendall(self):
        self.ais.sock = mox.MockAnything()
        self.m.StubOutWithMock(self.ais, "close")

        # part 1 not connected
        #
        # part 2 socket.error
        self.ais.sock.setblocking(mox.IgnoreArg())
        self.ais.sock.settimeout(mox.IgnoreArg())
        self.ais.sock.sendall(mox.IgnoreArg()).AndRaise(socket.error)
        self.ais.close()
        # part 3 empty input
        #

        mox.Replay(self.ais.sock)
        self.m.ReplayAll()

        # part 1
        self.ais._connected = False
        with self.assertRaises(aprslib.ConnectionError):
            self.ais.sendall("test")
        # part 2
        self.ais._connected = True
        with self.assertRaises(aprslib.ConnectionError):
            self.ais.sendall("test")

        # part 3
        self.ais._connected = True
        self.ais.sendall("")

        # verify so far
        mox.Verify(self.ais.sock)
        self.m.VerifyAll()

        # rest
        self.ais._connected = True
        for line in [
                "test",      # no \r\n
                "test\r\n",  # with \r\n
                u"test",     # unicode
                5,           # number or anything with __str__
                ]:
            # setup
            self.ais.sock = mox.MockAnything()
            self.ais.sock.setblocking(mox.IgnoreArg())
            self.ais.sock.settimeout(mox.IgnoreArg())
            self.ais.sock.sendall("%s\r\n" % str(line).rstrip('\r\n')).AndReturn(None)
            mox.Replay(self.ais.sock)

            self.ais.sendall(line)

            mox.Verify(self.ais.sock)
Пример #3
0
    def test_copy_image_to_volume(self):
        """resize_image common case usage."""
        mox = self._mox
        drv = self._driver

        TEST_IMG_SOURCE = 'foo.img'

        volume = {'size': self.TEST_SIZE_IN_GB, 'name': TEST_IMG_SOURCE}

        def fake_local_path(volume):
            return volume['name']

        self.stubs.Set(drv, 'local_path', fake_local_path)

        mox.StubOutWithMock(image_utils, 'fetch_to_raw')
        image_utils.fetch_to_raw(None, None, None, TEST_IMG_SOURCE)

        mox.StubOutWithMock(image_utils, 'resize_image')
        image_utils.resize_image(TEST_IMG_SOURCE, self.TEST_SIZE_IN_GB)

        mox.StubOutWithMock(image_utils, 'qemu_img_info')
        data = mox_lib.MockAnything()
        data.virtual_size = 1024**3
        image_utils.qemu_img_info(TEST_IMG_SOURCE).AndReturn(data)

        mox.ReplayAll()

        drv.copy_image_to_volume(None, volume, None, None)

        mox.VerifyAll()
Пример #4
0
 def setUp(self):
     super(TestBlockDeviceDriver, self).setUp()
     self.configuration = mox.MockAnything()
     self.configuration.available_devices = ['/dev/loop1', '/dev/loop2']
     self.configuration.host = 'localhost'
     self.configuration.iscsi_port = 3260
     self.drv = BlockDeviceDriver(configuration=self.configuration)
Пример #5
0
    def test_volume_attachment_updates_not_supported(self):
        self.m.StubOutWithMock(nova.NovaClientPlugin, 'get_server')
        nova.NovaClientPlugin.get_server(mox.IgnoreArg()).AndReturn(
            mox.MockAnything())
        fv = vt_base.FakeVolume('creating')
        fva = vt_base.FakeVolume('attaching')
        stack_name = 'test_volume_attach_updnotsup_stack'

        self._mock_create_volume(fv, stack_name)
        self._mock_create_server_volume_script(fva)
        self.stub_VolumeConstraint_validate()

        self.m.ReplayAll()

        stack = utils.parse_stack(self.t, stack_name=stack_name)

        self.create_volume(self.t, stack, 'DataVolume')
        rsrc = self.create_attachment(self.t, stack, 'MountPoint')

        props = copy.deepcopy(rsrc.properties.data)
        props['InstanceId'] = 'some_other_instance_id'
        props['VolumeId'] = 'some_other_volume_id'
        props['Device'] = '/dev/vdz'
        after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)

        update_task = scheduler.TaskRunner(rsrc.update, after)
        ex = self.assertRaises(exception.ResourceFailure, update_task)
        self.assertIn(
            'NotSupported: resources.MountPoint: '
            'Update to properties Device, InstanceId, '
            'VolumeId of MountPoint (AWS::EC2::VolumeAttachment)',
            six.text_type(ex))
        self.assertEqual((rsrc.UPDATE, rsrc.FAILED), rsrc.state)
        self.m.VerifyAll()
Пример #6
0
 def testSuccess(self):
   creds = mox.MockAnything()
   creds.apply(mox.IsA(dict))
   self.mox.ReplayAll()
   opener = base_client.BuildOauth2Opener(creds)
   self.mox.VerifyAll()
   self.assertIsInstance(opener, urllib2.OpenerDirector)
Пример #7
0
    def test_send_login(self):
        self.ais.sock = mox.MockAnything()
        self.m.StubOutWithMock(self.ais, "close")
        # part 1 - raises
        self.ais.sock.sendall(mox.IgnoreArg())
        self.ais.sock.settimeout(mox.IgnoreArg())
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("invalidreply")
        self.ais.close()
        # part 2 - raises (empty callsign)
        self.ais.sock.sendall(mox.IgnoreArg())
        self.ais.sock.settimeout(mox.IgnoreArg())
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("# logresp  verified, xx")
        self.ais.close()
        # part 3 - raises (callsign doesn't match
        self.ais.sock.sendall(mox.IgnoreArg())
        self.ais.sock.settimeout(mox.IgnoreArg())
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("# logresp NOMATCH verified, xx")
        self.ais.close()
        # part 4 - raises (unverified, but pass is not -1)
        self.ais.sock.sendall(mox.IgnoreArg())
        self.ais.sock.settimeout(mox.IgnoreArg())
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("# logresp CALL unverified, xx")
        self.ais.close()
        # part 5 - normal, receive only
        self.ais.sock.sendall(mox.IgnoreArg())
        self.ais.sock.settimeout(mox.IgnoreArg())
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("# logresp CALL unverified, xx")
        # part 6 - normal, correct pass
        self.ais.sock.sendall(mox.IgnoreArg())
        self.ais.sock.settimeout(mox.IgnoreArg())
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("# logresp CALL verified, xx")
        mox.Replay(self.ais.sock)
        self.m.ReplayAll()

        # part 1
        self.ais.set_login("CALL", "-1")
        self.assertRaises(aprslib.exceptions.LoginError, self.ais._send_login)
        # part 2
        self.ais.set_login("CALL", "-1")
        self.assertRaises(aprslib.exceptions.LoginError, self.ais._send_login)
        # part 3
        self.ais.set_login("CALL", "-1")
        self.assertRaises(aprslib.exceptions.LoginError, self.ais._send_login)
        # part 4
        self.ais.set_login("CALL", "99999")
        self.assertRaises(aprslib.exceptions.LoginError, self.ais._send_login)
        # part 5
        self.ais.set_login("CALL", "-1")
        self.ais._send_login()
        # part 6
        self.ais.set_login("CALL", "99999")
        self.ais._send_login()

        mox.Verify(self.ais.sock)
        self.m.VerifyAll()
Пример #8
0
    def test_close(self):
        self.ais._connected = True
        s = mox.MockAnything()
        s.close()
        self.ais.sock = s
        mox.Replay(s)

        self.ais.close()

        mox.Verify(s)
        self.assertFalse(self.ais._connected)
        self.assertEqual(self.ais.buf, '')
Пример #9
0
    def test_socket_readlines(self):
        fdr, fdw = os.pipe()
        f = os.fdopen(fdw,'w')
        f.write("something")
        f.close()

        self.m.ReplayAll()
        self.ais.sock = mox.MockAnything()
        # part 1 - conn drop before setblocking
        self.ais.sock.setblocking(0).AndRaise(socket.error)
        # part 2 - conn drop trying to recv
        self.ais.sock.setblocking(0)
        self.ais.sock.fileno().AndReturn(fdr)
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn('')
        # part 3 - nothing to read
        self.ais.sock.setblocking(0)
        self.ais.sock.fileno().AndReturn(fdr)
        self.ais.sock.recv(mox.IgnoreArg()).AndRaise(socket.error(""
                "Resource temporarily unavailable"))
        # part 4 - yield 3 lines (blocking False)
        self.ais.sock.setblocking(0)
        self.ais.sock.fileno().AndReturn(fdr)
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("a\r\n"*3)
        self.ais.sock.fileno().AndReturn(fdr)
        self.ais.sock.recv(mox.IgnoreArg()).AndRaise(socket.error(""
                "Resource temporarily unavailable"))
        # part 5 - yield 3 lines 2 times (blocking True)
        self.ais.sock.setblocking(0)
        self.ais.sock.fileno().AndReturn(fdr)
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("b\r\n"*3)
        self.ais.sock.fileno().AndReturn(fdr)
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("b\r\n"*3)
        self.ais.sock.fileno().AndReturn(fdr)
        self.ais.sock.recv(mox.IgnoreArg()).AndRaise(StopIteration)
        mox.Replay(self.ais.sock)

        # part 1
        with self.assertRaises(aprslib.exceptions.ConnectionDrop):
            self.ais._socket_readlines().next()
        # part 2
        with self.assertRaises(aprslib.exceptions.ConnectionDrop):
            self.ais._socket_readlines().next()
        # part 3
        with self.assertRaises(StopIteration):
            self.ais._socket_readlines().next()
        # part 4
        for line in self.ais._socket_readlines():
            self.assertEqual(line, 'a')
        # part 5
        for line in self.ais._socket_readlines(blocking=True):
            self.assertEqual(line, 'b')

        mox.Verify(self.ais.sock)
Пример #10
0
 def setUp(self):
     super(OpenVzConnTestCase, self).setUp()
     try:
         FLAGS.injected_network_template
     except AttributeError as err:
         flags.DEFINE_string('injected_network_template',
                             'nova/virt/interfaces.template',
                             'Stub for network template for testing purposes'
         )
     self.fake_file = mox.MockAnything()
     self.fake_file.readlines().AndReturn(FILECONTENTS.split())
     self.fake_file.writelines(mox.IgnoreArg())
     self.fake_file.read().AndReturn(FILECONTENTS)
Пример #11
0
    def test_filter(self):
        testFilter = "x/CALLSIGN"

        self.ais._connected = True
        s = mox.MockAnything()
        s.sendall("#filter %s\r\n" % testFilter)
        self.ais.sock = s
        mox.Replay(s)

        self.ais.set_filter(testFilter)
        self.assertEqual(self.ais.filter, testFilter)

        mox.Verify(s)
Пример #12
0
def test_app_wsgi():
    """Application instance works as a WSGI application."""
    app = wsgiservice.get_app(globals())
    env = Request.blank('/res1/theid.json').environ
    start_response = mox.MockAnything()
    start_response('200 OK',
                   [('Content-Length', '40'),
                    ('Content-Type', 'application/json; charset=UTF-8'),
                    ('Content-MD5', 'd6fe631718727b542d2ecb70dfd41e4b')])
    mox.Replay(start_response)
    res = app(env, start_response)
    print res
    mox.Verify(start_response)
    assert res == ['"GET was called with id theid, foo None"']
Пример #13
0
    def test_connect(self):
        self.ais.sock = mox.MockAnything()
        self.m.StubOutWithMock(self.ais, "_open_socket")
        self.m.StubOutWithMock(self.ais, "close")
        # part 1 - socket creation errors
        self.ais._open_socket().AndRaise(socket.timeout("timed out"))
        self.ais.close()
        self.ais._open_socket().AndRaise(socket.error('any'))
        self.ais.close()
        # part 2 - invalid banner from server
        self.ais._open_socket()
        self.ais.sock.getpeername().AndReturn((1, 2))
        self.ais.sock.setblocking(mox.IgnoreArg())
        self.ais.sock.settimeout(mox.IgnoreArg())
        self.ais.sock.setsockopt(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        if sys.platform not in ['cygwin', 'win32']:
            self.ais.sock.setsockopt(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
            self.ais.sock.setsockopt(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
            self.ais.sock.setsockopt(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("junk")
        self.ais.close()
        # part 3 - everything going well
        self.ais._open_socket()
        self.ais.sock.getpeername().AndReturn((1, 2))
        self.ais.sock.setblocking(mox.IgnoreArg())
        self.ais.sock.settimeout(mox.IgnoreArg())
        self.ais.sock.setsockopt(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        if sys.platform not in ['cygwin', 'win32']:
            self.ais.sock.setsockopt(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
            self.ais.sock.setsockopt(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
            self.ais.sock.setsockopt(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.ais.sock.recv(mox.IgnoreArg()).AndReturn("# server banner")
        mox.Replay(self.ais.sock)
        self.m.ReplayAll()

        # part 1
        self.assertRaises(aprslib.exceptions.ConnectionError, self.ais._connect)
        self.assertFalse(self.ais._connected)
        self.assertRaises(aprslib.exceptions.ConnectionError, self.ais._connect)
        self.assertFalse(self.ais._connected)
        # part 2
        self.assertRaises(aprslib.exceptions.ConnectionError, self.ais._connect)
        self.assertFalse(self.ais._connected)
        # part 3
        self.ais._connect()
        self.assertTrue(self.ais._connected)

        mox.Verify(self.ais.sock)
        self.m.VerifyAll()
Пример #14
0
    def set_up_pickling_class(self):
        class BasicMost(self.cls):
            name  = fields.Field()
            value = fields.Field()

        # Simulate a special module for this BasicMost, so pickle can find
        # the class for it.
        pickletest_module = mox.MockAnything()
        pickletest_module.BasicMost = BasicMost
        # Note this pseudomodule has no file, so coverage doesn't get a mock
        # method by mistake.
        pickletest_module.__file__ = None
        BasicMost.__module__ = 'remoteobjects._pickletest'
        sys.modules['remoteobjects._pickletest'] = pickletest_module

        return BasicMost
Пример #15
0
    def testTwoTries(self):
        """Test a two try cache."""
        original = mox.MockAnything()
        original.getHostByName('google.com').AndReturn(
            defer.fail(
                failure.Failure(error.DNSLookupError('Fake DNS failure'))))
        original.getHostByName('google.com').AndReturn(
            defer.succeed('1.2.3.4'))
        mox.Replay(original)

        cache = dnsRetry.RetryingDNS(original,
                                     tries=2,
                                     sleep=time.SleepManager(0, 0, 0))
        result = cache.getHostByName('google.com')
        self.assertEquals(result, '1.2.3.4')
        mox.Verify(original)
Пример #16
0
  def testFallbackFailsFirstTime(self):
    """Test a cache with fallback."""
    original = mox.MockAnything()
    original.getHostByName('google.com').AndReturn(
        defer.fail(failure.Failure(error.DNSLookupError('Fake DNS failure'))))
    original.getHostByName('google.com').AndReturn(
        defer.succeed('1.2.3.4'))
    mox.Replay(original)

    cache = dnsCache.CachingDNS(original, timeout = 1)
    result = cache.getHostByName('google.com')
    self.assertTrue(isinstance(result.result, failure.Failure))
    result.addErrback(lambda _: None) # Consume the error.
    result = cache.getHostByName('google.com')
    self.assertEquals(result.result, '1.2.3.4')
    mox.Verify(original)
Пример #17
0
    def testOneTry(self):
        """Test a single try cache."""
        original = mox.MockAnything()
        original.getHostByName('google.com').AndReturn(
            defer.fail(
                failure.Failure(error.DNSLookupError('Fake DNS failure'))))
        original.getHostByName('google.com').AndReturn(
            defer.succeed('1.2.3.4'))
        mox.Replay(original)

        cache = dnsRetry.RetryingDNS(original, tries=1)
        self.assertRaises(error.DNSLookupError, cache.getHostByName,
                          'google.com')

        result = cache.getHostByName('google.com')
        self.assertEquals(result, '1.2.3.4')
        mox.Verify(original)
Пример #18
0
    def testWithEncryptedVolumes(self):
        self.mox.StubOutClassWithMocks(main.tkinter, 'GuiOauth')
        gui = main.tkinter.GuiOauth('https://cvest.appspot.com')
        gui.EncryptedVolumePrompt()

        self.mox.StubOutWithMock(main.corestorage, 'GetStateAndVolumeIds')
        main.corestorage.GetStateAndVolumeIds().AndReturn(
            (None, ['mock_volume_id'], []))

        opts = mox.MockAnything()
        opts.login_type = 'oauth2'
        opts.oauth2_client_id = 'stub_id'
        opts.oauth2_client_secret = 'stub_secret'
        opts.server_url = 'https://cvest.appspot.com'

        self.mox.ReplayAll()
        main.main(opts)
        self.mox.VerifyAll()
Пример #19
0
    def setUp(self):
        self.m = mox.Mox()
        self.m.StubOutWithMock(utils.config, 'get')
        utils.config.get(
            'CONTRAIL', 'contrail_url').AndReturn(test_data.contrail_url)
        utils.config.get(
            'COMMON', 'os_auth_url').AndReturn(test_data.os_auth_url)
        utils.config.get(
            'COMMON', 'os_username').AndReturn(test_data.os_username)
        utils.config.get(
            'COMMON', 'os_password').AndReturn(test_data.os_password)
        utils.config.get(
            'COMMON', 'os_user_domain_name').AndReturn(test_data.os_user_domain_name)
        utils.config.get(
            'COMMON', 'os_project_name').AndReturn(test_data.os_project_name)
        utils.config.get(
            'COMMON', 'os_project_domain_name').AndReturn(test_data.os_project_domain_name)
        utils.config.get(
            'COMMON', 'os_region').AndReturn(test_data.os_region)
        self.m.StubOutWithMock(Password, 'load_from_options')
        self.mock_password = self.m.CreateMock(Password)
        Password.load_from_options(auth_url=mox.IgnoreArg(), password=mox.IgnoreArg(),
                                   project_domain_name=mox.IgnoreArg(),
                                   project_name=mox.IgnoreArg(), user_domain_name=mox.IgnoreArg(),
                                   username=mox.IgnoreArg()
                                  ).AndReturn(self.mock_password)

        self.m.StubOutWithMock(session, 'Session')
        session.Session(auth=self.mock_password).AndReturn(None)
        self.m.StubOutWithMock(nova, 'Client')
        self.mock_nova_client = mox.MockAnything()
        nova.Client(mox.IgnoreArg(), session=mox.IgnoreArg(), region_name=mox.IgnoreArg()
                   ).AndReturn(self.mock_nova_client)

        self.m.ReplayAll()
        self.ipinfo = utils.IpInfoCorrelator()
        self.m.VerifyAll()
        self.m.UnsetStubs()

        # Set up mock instance for individual test case
        self.m.StubOutWithMock(httplib2, 'Http')
        self.mock_http = self.m.CreateMock(httplib2.Http)
        self.m.StubOutWithMock(self.ipinfo.nova_client, 'servers')
        self.m.StubOutWithMock(self.ipinfo.nova_client.servers, 'list')
Пример #20
0
  def testFallback(self):
    """Test a cache with fallback."""
    original = mox.MockAnything()
    original.getHostByName('google.com').AndReturn(
        defer.succeed('1.2.3.4'))
    original.getHostByName('google.com').AndReturn(
        defer.fail(failure.Failure(error.DNSLookupError('Fake DNS failure'))))
    original.getHostByName('google.com').AndReturn(
        defer.succeed('9.8.7.6'))
    mox.Replay(original)

    cache = dnsCache.CachingDNS(original, timeout = 0)
    result = cache.getHostByName('google.com')
    self.assertEquals(result.result, '1.2.3.4')
    result = cache.getHostByName('google.com')
    self.assertEquals(result.result, '1.2.3.4')
    result = cache.getHostByName('google.com')
    self.assertEquals(result.result, '9.8.7.6')
    mox.Verify(original)
Пример #21
0
 def setUp(self):
     super(TestLauncher, self).setUp()
     self.stubs.Set(wsgi.Loader, "load_app", mox.MockAnything())
     self.service = service.WSGIService("test_service")
Пример #22
0
 def setUp(self):
     super(TestWSGIService, self).setUp()
     self.stubs.Set(wsgi.Loader, "load_app", mox.MockAnything())
Пример #23
0
 def setUp(self):
     resetTimeSourceForTestingPurposes(global_time)
     self.mock_leg_model = mox.MockAnything()
Пример #24
0
 def __init__(self):
     self.conductor_api = mox.MockAnything()
     self.db = mox.MockAnything()
Пример #25
0
 def setUp(self):
     self.mockJoint = mox.MockAnything()
     self.control = joint_control.JointController(self.mockJoint)
     self.control.prev_time = 0
Пример #26
0
 def setUp(self):
   self.mock_object = mox.MockAnything()
Пример #27
0
 def testEqualsMockFailure(self):
   """Verify equals identifies unequal objects."""
   self.mock_object.SillyCall()
   self.mock_object._Replay()
   self.assertNotEquals(self.mock_object, mox.MockAnything())