Example #1
0
  def testUndeployWithCloudAppScalefile(self):
    # calling 'appscale undeploy app' with an AppScalefile in the local
    # directory should collect any parameters needed for the
    # 'appscale-remove-app' command and then exec it
    appscale = AppScale()

    # Mock out the actual file reading itself, and slip in a YAML-dumped
    # file
    contents = {
      'infrastructure' : 'ec2',
      'machine' : 'ami-ABCDEFG',
      'keyname' : 'bookey',
      'group' : 'boogroup',
      'verbose' : True,
      'min_machines' : 1,
      'max_machines' : 1
    }
    yaml_dumped_contents = yaml.dump(contents)
    self.addMockForAppScalefile(appscale, yaml_dumped_contents)

    # finally, mock out the actual appscale-run-instances call
    flexmock(AppScaleTools)
    AppScaleTools.should_receive('remove_app')
    app = 'barapp'
    appscale.undeploy(app)
  def test_appscale_with_ips_layout_flag_but_no_copy_id(self):
    # assume that we have ssh-keygen but not ssh-copy-id
    flexmock(subprocess)
    subprocess.should_receive('Popen').with_args(re.compile('hash ssh-keygen'),
      shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
      .and_return(self.success)

    flexmock(subprocess)
    subprocess.should_receive('Popen').with_args(re.compile('hash ssh-copy-id'),
      shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
      .and_return(self.failed)

    # don't use a 192.168.X.Y IP here, since sometimes we set our virtual
    # machines to boot with those addresses (and that can mess up our tests).
    ips_layout = yaml.safe_load("""
master : public1
database: public1
zookeeper: public2
appengine:  public3
    """)

    argv = [
      "--ips_layout", base64.b64encode(yaml.dump(ips_layout)),
      "--keyname", self.keyname
    ]
    options = ParseArgs(argv, self.function).args
    self.assertRaises(BadConfigurationException, AppScaleTools.add_keypair,
      options)
  def test_table_flags(self):
    # throw in a mock that says our ips.yaml file exists
    flexmock(os.path)
    os.path.should_call('exists')  # set the fall-through
    os.path.should_receive('exists').with_args('ips.yaml').and_return(True)

    # Specifying a table that isn't accepted should abort
    argv_1 = self.cluster_argv[:] + ['--table', 'non-existent-database']
    self.assertRaises(SystemExit, ParseArgs, argv_1, self.function)

    # Specifying a table that is accepted should return that in the result
    argv_2 = self.cluster_argv[:] + ['--table', 'cassandra']
    actual_2 = ParseArgs(argv_2, self.function)
    self.assertEquals('cassandra', actual_2.args.table)

    # Failing to specify a table should default to a predefined table
    args_3 = self.cluster_argv[:]
    actual_3 = ParseArgs(args_3, self.function)
    self.assertEquals(ParseArgs.DEFAULT_DATASTORE, actual_3.args.table)

    # Specifying a non-positive integer for n should abort
    argv_4 = self.cloud_argv[:] + ['--table', 'cassandra', '-n', '0']
    self.assertRaises(BadConfigurationException, ParseArgs, argv_4,
      self.function)

    # Specifying a positive integer for n should be ok
    argv_5 = self.cloud_argv[:] + ['--table', 'cassandra', '-n', '2']
    actual_5 = ParseArgs(argv_5, self.function)
    self.assertEquals(2, actual_5.args.replication)
Example #4
0
  def testDeployWithCloudAppScalefileAndTestFlag(self):
    # same as before, but with the 'test' flag in our AppScalefile
    appscale = AppScale()

    # Mock out the actual file reading itself, and slip in a YAML-dumped
    # file
    contents = {
      'infrastructure' : 'ec2',
      'machine' : 'ami-ABCDEFG',
      'keyname' : 'bookey',
      'group' : 'boogroup',
      'verbose' : True,
      'min_machines' : 1,
      'max_machines' : 1,
      'test' : True
    }
    yaml_dumped_contents = yaml.dump(contents)
    self.addMockForAppScalefile(appscale, yaml_dumped_contents)

    # finally, mock out the actual appscale-run-instances call
    fake_port = 8080
    fake_host = 'fake_host'
    flexmock(AppScaleTools)
    AppScaleTools.should_receive('upload_app').and_return(
      (fake_host, fake_port))
    AppScaleTools.should_receive('update_indexes')
    AppScaleTools.should_receive('update_cron')
    AppScaleTools.should_receive('update_queues')
    app = '/bar/app'
    (host, port) = appscale.deploy(app)
    self.assertEquals(fake_host, host)
    self.assertEquals(fake_port, port)
  def test_infrastructure_flags(self):
    # Specifying infastructure as EC2 or Eucalyptus is acceptable.
    argv_1 = self.cloud_argv[:] + ['--infrastructure', 'ec2', '--machine',
      'ami-ABCDEFG']
    actual_1 = ParseArgs(argv_1, self.function)
    self.assertEquals('ec2', actual_1.args.infrastructure)

    argv_2 = self.cloud_argv[:] + ['--infrastructure', 'euca', '--machine',
        'emi-ABCDEFG']
    actual_2 = ParseArgs(argv_2, self.function)
    self.assertEquals('euca', actual_2.args.infrastructure)

    # Specifying something else as the infrastructure is not acceptable.
    argv_3 = self.cloud_argv[:] + ['--infrastructure', 'boocloud', '--machine',
      'boo']
    self.assertRaises(SystemExit, ParseArgs, argv_3, self.function)

    # Specifying --machine when we're not running in a cloud is not acceptable.
    flexmock(os.path)
    os.path.should_call('exists')  # set the fall-through
    os.path.should_receive('exists').with_args("ips.yaml").and_return(True)

    argv_4 = self.cluster_argv[:] + ['--machine', 'boo']
    self.assertRaises(BadConfigurationException, ParseArgs, argv_4,
      self.function)
Example #6
0
    def testLongName(self):
        def check(uid, name, variant, exp_logdir):
            tst = DummyTest("test", test.TestName(uid, name, variant))
            self.assertEqual(os.path.basename(tst.logdir), exp_logdir)
            return tst

        # Everything fits
        check(1, "a" * 253, None, "1-" + ("a" * 253))
        check(2, "a" * 251, 1, "2-" + ("a" * 251) + ";1")
        check(99, "a" * 249, 88, "99-" + ("a" * 249) + ";88")
        # Shrink name
        check(3, "a" * 252, 1, "3-" + ('a' * 251) + ";1")
        # Shrink variant
        check("a" * 253, "whatever", 99, "a" * 253 + ";9")
        check("a" * 254, "whatever", 99, "a" * 254 + ";")
        # No variant
        tst = check("a" * 255, "whatever", "whatever-else", "a" * 255)
        # Impossible to store (uid does not fit
        self.assertRaises(AssertionError, check, "a" * 256, "whatever", "else",
                          None)

        self.assertEqual(os.path.basename(tst.workdir),
                         os.path.basename(tst.logdir))
        flexmock(tst)
        tst.should_receive('filename').and_return(os.path.join(self.tmpdir,
                                                               "a"*250))
        self.assertEqual(os.path.join(self.tmpdir, "a"*250 + ".data"),
                         tst.datadir)
        tst.should_receive('filename').and_return("a"*251)
        self.assertFalse(tst.datadir)
        tst._record_reference_stdout       # Should does nothing
        tst._record_reference_stderr       # Should does nothing
        tst._record_reference_stdout()
        tst._record_reference_stderr()
Example #7
0
def test_run__exception__create_temp_dir():
    cfg_mock = flexmock(temp_root = _DUMMY_TEMP_ROOT)
    node_mock = flexmock(Node())
    node_mock.should_receive('_create_temp_dir').with_args(cfg_mock) \
      .and_raise(OSError()).ordered.once

    assert_raises(NodeUnhandledException, node_mock.run, cfg_mock) # pylint: disable=E1103
Example #8
0
 def setUp(self):
     Remote = flexmock()
     remote_remote = flexmock(remoter)
     (remote_remote.should_receive('Remote')
      .with_args(hostname='hostname', username='******',
                 password='******', key_filename=None, port=22,
                 timeout=60, env_keep=None)
      .once().ordered()
      .and_return(Remote))
     Args = flexmock(test_result_total=1,
                     url=['/tests/sleeptest', '/tests/other/test',
                          'passtest'],
                     remote_username='******',
                     remote_hostname='hostname',
                     remote_port=22,
                     remote_password='******',
                     remote_key_file=None,
                     remote_no_copy=False,
                     remote_timeout=60,
                     show_job_log=False,
                     env_keep=None)
     log = flexmock()
     log.should_receive("info")
     job = flexmock(args=Args, log=log)
     self.runner = remote.RemoteTestRunner(job, None)
Example #9
0
  def test_run(self):
    zookeeper = flexmock()
    ds_factory = flexmock(appscale_datastore_batch.DatastoreFactory)
    ds_factory.should_receive("getDatastore").and_return(FakeDatastore())
    fake_backup = flexmock(backup.DatastoreBackup('app_id', zookeeper,
      "cassandra", False, []))
    fake_backup.should_receive('set_filename').and_return()
    fake_backup.should_receive('backup_source_code').at_most().times(1).\
      and_return()

    # Test with failure to get the backup lock.
    fake_backup.should_receive('get_backup_lock').and_return(False)
    flexmock(time).should_receive('sleep').and_return()

    # Test with successfully obtaining the backup lock.
    fake_backup.should_receive('get_backup_lock').and_return('some/path')
    fake_backup.should_receive('run_backup').and_return()

    # ... and successfully releasing the lock.
    zookeeper.should_receive('release_lock_with_path').and_return(True)
    self.assertEquals(None, fake_backup.run())

    # ... and failure to release the lock.
    zookeeper.should_receive('release_lock_with_path').\
      and_raise(ZKTransactionException)
    self.assertEquals(None, fake_backup.run())
Example #10
0
 def testGeneratePodSpecificDhcpConfWithSerial(self):
     from jnpr.openclos.l3Clos import util
     flexmock(util, isPlatformUbuntu = True)
     
     with self._dao.getReadWriteSession() as session:
         pod = createPod('pod1', session)
         pod.spineJunosImage = 'testSpineImage'
         
         createPodDevice(session, 'dev1', pod)
         dev2 = createPodDevice(session, 'dev2', pod)
         dev2.macAddress = None
         dev2.serialNumber = 'VB1234567890'
         dev3 = createPodDevice(session, 'dev3', pod)
         dev3.role = 'leaf'
         dev3.serialNumber = 'VB1234567891'
       
         dhcpConf = self.ztpServer.generatePodSpecificDhcpConf(session, pod.id)
         print dhcpConf
     self.assertEquals(2, dhcpConf.count('testSpineImage'))
     self.assertFalse('{{' in dhcpConf)
     self.assertFalse('}}' in dhcpConf)
     self.assertFalse('None' in dhcpConf)
     self.assertTrue('VB1234567890' in dhcpConf)
     self.assertTrue('VB1234567891' not in dhcpConf)
     self.assertEquals(5, dhcpConf.count('host-name')) # 1 global class + 1 subnet + 2 device mac + 1 device serial
Example #11
0
    def testGeneratePodSpecificDhcpConfFor2StageZtp(self):
        from jnpr.openclos.l3Clos import util
        flexmock(util, isPlatformUbuntu = True)
        flexmock(util, isZtpStaged = True)
        with self._dao.getReadWriteSession() as session:
            pod = createPod('pod1', session)
            pod.spineJunosImage = 'testSpineImage'
            pod.leafSettings.append(LeafSetting('ex4300-24p', pod.id))
            
            dev1 = createPodDevice(session, 'dev1', pod)
            dev2 = createPodDevice(session, 'dev2', pod)
            dev3 = createPodDevice(session, 'dev3', pod)
            dev3.role = 'leaf'
            dev4 = createPodDevice(session, 'dev4', pod)
            dev4.role = 'leaf'
          
            dhcpConf = self.ztpServer.generatePodSpecificDhcpConf(session, pod.id)

        self.assertEquals(2, dhcpConf.count('testSpineImage'))

        self.assertFalse('{{' in dhcpConf)
        self.assertFalse('}}' in dhcpConf)
        self.assertFalse('None' in dhcpConf)
        self.assertEquals(3, dhcpConf.count('host-name')) # 1 global + 2 spine device
        self.assertEquals(1, dhcpConf.count('pool'))
        self.assertEquals(2, dhcpConf.count('class '))
        self.assertEquals(4, dhcpConf.count('vendor-class-identifier'))
  def test_put_entities(self):
    app_id = 'test'
    db_batch = flexmock()
    db_batch.should_receive('valid_data_version_sync').and_return(True)

    entity_proto1 = self.get_new_entity_proto(
      app_id, "test_kind", "bob", "prop1name", "prop1val", ns="blah")
    entity_key1 = 'test\x00blah\x00test_kind:bob\x01'
    entity_proto2 = self.get_new_entity_proto(
      app_id, "test_kind", "nancy", "prop1name", "prop2val", ns="blah")
    entity_key2 = 'test\x00blah\x00test_kind:nancy\x01'
    entity_list = [entity_proto1, entity_proto2]
    async_result = gen.Future()
    async_result.set_result({entity_key1: {}, entity_key2: {}})

    db_batch.should_receive('batch_get_entity').and_return(async_result)
    db_batch.should_receive('normal_batch').and_return(ASYNC_NONE)
    transaction_manager = flexmock(
      create_transaction_id=lambda project, xg: 1,
      delete_transaction_id=lambda project, txid: None,
      set_groups=lambda project, txid, groups: None)
    dd = DatastoreDistributed(db_batch, transaction_manager,
                              self.get_zookeeper())
    dd.index_manager = flexmock(
      projects={app_id: flexmock(indexes_pb=[])})

    async_true = gen.Future()
    async_true.set_result(True)
    entity_lock = flexmock(EntityLock)
    entity_lock.should_receive('acquire').and_return(async_true)
    entity_lock.should_receive('release')

    yield dd.put_entities(app_id, entity_list)
  def test_delete_entities(self):
    app_id = 'test'
    entity_proto1 = self.get_new_entity_proto(
      app_id, "test_kind", "bob", "prop1name", "prop1val", ns="blah")
    row_key = "test\x00blah\x00test_kind:bob\x01"
    row_values = {row_key: {APP_ENTITY_SCHEMA[0]: entity_proto1.Encode(),
                            APP_ENTITY_SCHEMA[1]: '1'}}
    async_result = gen.Future()
    async_result.set_result(row_values)

    zk_client = flexmock()
    zk_client.should_receive('add_listener')

    zookeeper = flexmock(handle=zk_client)
    zookeeper.should_receive("get_valid_transaction_id").and_return(1)
    db_batch = flexmock()
    db_batch.should_receive('valid_data_version_sync').and_return(True)
    db_batch.should_receive("batch_get_entity").and_return(async_result)
    db_batch.should_receive('normal_batch').and_return(ASYNC_NONE)

    transaction_manager = flexmock()
    dd = DatastoreDistributed(db_batch, transaction_manager, zookeeper)

    row_keys = [entity_proto1.key()]

    yield dd.delete_entities(entity_proto1.key(), 1, row_keys)
  def test_create_composite_index(self):
    db_batch = flexmock()
    db_batch.should_receive('valid_data_version_sync').and_return(True)
    db_batch.should_receive("batch_put_entity").and_return(ASYNC_NONE)
    transaction_manager = flexmock()
    dd = DatastoreDistributed(db_batch, transaction_manager,
                              self.get_zookeeper())
    zk_handle = flexmock(ensure_path=lambda path: None,
                         get=lambda path: (None, flexmock(version=None)),
                         set=lambda path, value, version: None)
    dd.zookeeper.handle = zk_handle
    dd = flexmock(dd)
    index = entity_pb.CompositeIndex()
    index.set_app_id("appid")
    index.set_state(2)
    definition = index.mutable_definition()
    definition.set_entity_type("kind")
    definition.set_ancestor(0)
    prop1 = definition.add_property()
    prop1.set_name("prop1")
    prop1.set_direction(1) # ascending
    prop2 = definition.add_property()
    prop2.set_name("prop2")
    prop1.set_direction(1) # ascending

    index_id = yield dd.create_composite_index("appid", index)
    assert index_id > 0
  def test_insert_composite_indexes(self):
    composite_index = entity_pb.CompositeIndex()
    composite_index.set_id(123)
    composite_index.set_app_id("appid")

    definition = composite_index.mutable_definition()
    definition.set_entity_type("kind")

    prop1 = definition.add_property()
    prop1.set_name("prop1")
    prop1.set_direction(1) # ascending
    prop2 = definition.add_property()
    prop2.set_name("prop2")
    prop1.set_direction(1) # ascending

    ent = self.get_new_entity_proto(
      "appid", "kind", "entity_name", "prop1", "value", ns="")

    db_batch = flexmock()
    db_batch.should_receive('valid_data_version_sync').and_return(True)
    db_batch.should_receive("batch_put_entity").and_return(ASYNC_NONE).once()
    transaction_manager = flexmock()
    dd = DatastoreDistributed(db_batch, transaction_manager,
                              self.get_zookeeper())
    yield dd.insert_composite_indexes([ent], [composite_index])
def mock_koji_session(koji_proxyuser=None, koji_ssl_certs_dir=None,
                      koji_krb_principal=None, koji_krb_keytab=None):
    session = flexmock()
    session.should_receive('buildImageOz').and_return(1234567)
    session.should_receive('taskFinished').and_return(True)
    session.should_receive('getTaskInfo').and_return({
        'state': koji_util.koji.TASK_STATES['CLOSED']
    })
    session.should_receive('listTaskOutput').and_return([
        'fedora-23-1.0.tar.gz',
    ])
    session.should_receive('getTaskChildren').and_return([
        {'id': 1234568},
    ])
    session.should_receive('downloadTaskOutput').and_return('tarball-contents')
    koji_auth_info = {
        'proxyuser': koji_proxyuser,
        'ssl_certs_dir': koji_ssl_certs_dir,
        'krb_principal': koji_krb_principal,
        'krb_keytab': koji_krb_keytab,
    }

    (flexmock(koji_util)
        .should_receive('create_koji_session')
        .once()
        .with_args(KOJI_HUB, koji_auth_info)
        .and_return(session))
  def test_get_composite_index_key(self):
    db_batch = flexmock()
    db_batch.should_receive('valid_data_version_sync').and_return(True)
    transaction_manager = flexmock()
    dd = DatastoreDistributed(db_batch, transaction_manager,
                              self.get_zookeeper())
    dd = flexmock(dd)

    composite_index = entity_pb.CompositeIndex()
    composite_index.set_id(123)
    composite_index.set_app_id("appid")

    definition = composite_index.mutable_definition()
    definition.set_entity_type("kind")

    prop1 = definition.add_property()
    prop1.set_name("prop1")
    prop1.set_direction(1) # ascending
    prop2 = definition.add_property()
    prop2.set_name("prop2")
    prop1.set_direction(1) # ascending

    ent = self.get_new_entity_proto("appid", "kind", "entity_name", "prop1", "value", ns="")

    self.assertEquals(
      dd.get_composite_index_key(composite_index, ent),
      "appid\x00\x00123\x00\x9avalue\x01\x01\x00\x00kind:entity_name\x01")
def test_add_labels_plugin_generated(tmpdir, docker_tasker, auto_label, value_re_part):
    df = df_parser(str(tmpdir))
    df.content = DF_CONTENT

    if MOCK:
        mock_docker()

    workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image')
    setattr(workflow, 'builder', X)
    flexmock(workflow, source=MockSource())
    flexmock(workflow, base_image_inspect=LABELS_CONF_BASE)
    setattr(workflow.builder, 'df_path', df.dockerfile_path)

    runner = PreBuildPluginsRunner(
        docker_tasker,
        workflow,
        [{
            'name': AddLabelsPlugin.key,
            'args': {'labels': {}, "dont_overwrite": [], "auto_labels": [auto_label],
                     'aliases': {'Build_Host': 'com.redhat.build-host'}}
        }]
    )

    runner.run()
    if value_re_part:
        assert re.match(value_re_part, df.labels[auto_label])

    if auto_label == "build-date":
        utc_dt = datetime.datetime.utcfromtimestamp(atomic_reactor_start_time).isoformat()
        assert df.labels[auto_label] == utc_dt
def test_add_labels_plugin_explicit(tmpdir, docker_tasker, auto_label, labels_docker, labels_base):
    df = df_parser(str(tmpdir))
    df.content = labels_docker

    if MOCK:
        mock_docker()

    workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image')
    setattr(workflow, 'builder', X)
    flexmock(workflow, source=MockSource())
    flexmock(workflow, base_image_inspect=labels_base)
    setattr(workflow.builder, 'df_path', df.dockerfile_path)

    prov_labels = {}
    prov_labels[auto_label] = 'explicit_value'

    runner = PreBuildPluginsRunner(
        docker_tasker,
        workflow,
        [{
            'name': AddLabelsPlugin.key,
            'args': {'labels': prov_labels, "dont_overwrite": [], "auto_labels": [auto_label],
                     'aliases': {'Build_Host': 'com.redhat.build-host'}}
        }]
    )

    runner.run()

    assert df.labels[auto_label] == 'explicit_value'
  def setUp(self):
    self.keyname = "boobazblargfoo"
    self.function = "appscale-upload-app"
    self.app_dir = "/tmp/baz/gbaz"

    # mock out any writing to stdout
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()
    AppScaleLogger.should_receive('success').and_return()

    # mock out all sleeping
    flexmock(time)
    time.should_receive('sleep').and_return()

    local_state = flexmock(LocalState)
    local_state.should_receive('shell').and_return()

    # throw some default mocks together for when invoking via shell succeeds
    # and when it fails
    self.fake_temp_file = flexmock(name='fake_temp_file')
    self.fake_temp_file.should_receive('read').and_return('boo out')
    self.fake_temp_file.should_receive('close').and_return()
    self.fake_temp_file.should_receive('seek').with_args(0).and_return()

    flexmock(tempfile)
    tempfile.should_receive('NamedTemporaryFile').and_return(self.fake_temp_file)

    self.success = flexmock(name='success', returncode=0)
    self.success.should_receive('wait').and_return(0)

    self.failed = flexmock(name='success', returncode=1)
    self.failed.should_receive('wait').and_return(1)
def prepare(key, value, set_labels_args=None, set_labels_kwargs=None):
    tasker = DockerTasker()
    workflow = DockerBuildWorkflow(SOURCE, "test-image")
    setattr(workflow, 'builder', X())
    setattr(workflow.builder, 'image_id', 'asd123')
    setattr(workflow.builder, 'base_image', ImageName(repo='Fedora', tag='22'))
    setattr(workflow.builder, 'source', X())
    setattr(workflow.builder.source, 'path', '/tmp')
    setattr(workflow.builder.source, 'dockerfile_path', None)
    # No-op implementation until implemented in osbs-client
    flexmock(OSBS)
    setattr(OSBS, 'set_labels_on_build_config', lambda **kwargs: None)
    expectation = flexmock(OSBS).should_receive('set_labels_on_build_config')
    if set_labels_args is not None:
        if set_labels_kwargs is None:
            set_labels_kwargs = {}

        expectation.with_args(*set_labels_args, **set_labels_kwargs)

    runner = PreBuildPluginsRunner(tasker, workflow,
                                   [
                                       {
                                           'name': CheckAndSetRebuildPlugin.key,
                                           'args': {
                                               'label_key': key,
                                               'label_value': value,
                                               'url': '',
                                           },
                                       }
                                   ])
    return workflow, runner
  def test_upload_java_app_with_no_appid(self):
    # if the user gives us an app with a reserved appid, we should abort

    # add in mocks so that there is an appengine-web.xml, but with no appid set
    flexmock(os.path)
    os.path.should_call('exists')
    os.path.should_receive('exists').with_args(
      AppEngineHelper.get_app_yaml_location(self.app_dir)).and_return(False)
    appengine_web_xml_location = AppEngineHelper.get_appengine_web_xml_location(
      self.app_dir)
    os.path.should_receive('exists').with_args(
      AppEngineHelper.get_appengine_web_xml_location(self.app_dir)).and_return(True)

    # mock out reading the app.yaml file
    builtins = flexmock(sys.modules['__builtin__'])
    builtins.should_call('open')  # set the fall-through

    fake_appengine_web_xml = flexmock(name="fake_appengine_web_xml")
    fake_appengine_web_xml.should_receive('read').and_return("<baz></baz>\n" +
      "<application></application>")
    builtins.should_receive('open').with_args(appengine_web_xml_location, 'r') \
      .and_return(fake_appengine_web_xml)

    argv = [
      "--keyname", self.keyname,
      "--file", self.app_dir
    ]
    options = ParseArgs(argv, self.function).args
    self.assertRaises(AppEngineConfigException, AppScaleTools.upload_app, options)
Example #23
0
  def test_register_updated_key(self):
    # mock out getTransactionRootPath
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('get_valid_transaction_path').\
      and_return('/txn/path')
    zk.ZKTransaction.should_receive('get_transaction_path').\
      and_return('/txn/path')

    zk.ZKTransaction.should_receive('get_blacklist_root_path').\
      and_return("bl_root_path")

    # mock out initializing a ZK connection
    fake_zookeeper = flexmock(name='fake_zoo')
    fake_zookeeper.should_receive('start')
    fake_zookeeper.should_receive('exists').and_return(True)
    fake_zookeeper.should_receive('acreate')
    fake_zookeeper.should_receive('set_async')

    flexmock(kazoo.client)
    kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)

    transaction = zk.ZKTransaction(host="something", start_gc=False)
    self.assertEquals(True, transaction.register_updated_key(self.appid, 
      "1", "2", "somekey"))

    fake_zookeeper.should_receive('exists').and_return(False)
    self.assertRaises(ZKTransactionException, 
      transaction.register_updated_key, self.appid, "1", "2", "somekey")
Example #24
0
  def test_create_sequence_node(self):
    # mock out getTransactionRootPath
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('get_transaction_prefix_path').with_args(
      self.appid).and_return('/rootpath')
    
    # mock out initializing a ZK connection
    fake_zookeeper = flexmock(name='fake_zoo', create='baz')
    fake_zookeeper.should_receive('start')

    # mock out zookeeper.create for txn id
    path_to_create = "/rootpath/" + self.appid
    zero_path = path_to_create + "/0"
    nonzero_path = path_to_create + "/1"
    zk.ZKTransaction.should_receive('run_with_timeout').and_return(zero_path) \
      .and_return(nonzero_path)

    # mock out deleting the zero id we get the first time around
    fake_zookeeper.should_receive('delete_async').with_args(zero_path)

    flexmock(kazoo.client)
    kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)

    # assert, make sure we got back our id
    transaction = zk.ZKTransaction(host="something", start_gc=False)
    self.assertEquals(1, transaction.create_sequence_node('/rootpath/' + \
      self.appid, 'now'))
Example #25
0
  def test_release_lock(self):
    # mock out getTransactionRootPath
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('check_transaction')
    zk.ZKTransaction.should_receive('get_transaction_path').\
      and_return('/rootpath')
    zk.ZKTransaction.should_receive('get_transaction_lock_list_path').\
      and_return('/rootpath')
    zk.ZKTransaction.should_receive('is_xg').and_return(False)

    # mock out initializing a ZK connection
    fake_zookeeper = flexmock(name='fake_zoo')
    fake_zookeeper.should_receive('start')
    fake_zookeeper.should_receive('exists').and_return(True)
    fake_zookeeper.should_receive('get').and_return(['/1/2/3'])
    fake_zookeeper.should_receive('delete_async')
    fake_zookeeper.should_receive('delete')
    fake_zookeeper.should_receive('get_children').and_return(['1','2'])

    flexmock(kazoo.client)
    kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)

    transaction = zk.ZKTransaction(host="something", start_gc=False)
    self.assertEquals(True, transaction.release_lock(self.appid, 1))

    zk.ZKTransaction.should_receive('is_xg').and_return(True)
    self.assertEquals(True, transaction.release_lock(self.appid, 1))

    # Check to make sure it raises exception for blacklisted transactions.
    zk.ZKTransaction.should_receive('is_xg').and_return(False)
    fake_zookeeper.should_receive('get').and_raise(kazoo.exceptions.NoNodeError)
    self.assertRaises(zk.ZKTransactionException, transaction.release_lock,
      self.appid, 1)
Example #26
0
  def test_is_in_transaction(self):
    # shared mocks
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('get_transaction_path') \
      .and_return('/transaction/path')

    fake_zookeeper = flexmock(name='fake_zoo')
    fake_zookeeper.should_receive('start')

    flexmock(kazoo.client)
    kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)

    # test when the transaction is running
    zk.ZKTransaction.should_receive('is_blacklisted').and_return(False)
    fake_zookeeper.should_receive('exists').and_return(True)
    transaction = zk.ZKTransaction(host="something", start_gc=False)
    self.assertEquals(True, transaction.is_in_transaction(self.appid, 1))

    # and when it's not
    zk.ZKTransaction.should_receive('is_blacklisted').and_return(False)
    fake_zookeeper.should_receive('exists').and_return(False)
    transaction = zk.ZKTransaction(host="something", start_gc=False)
    self.assertEquals(False, transaction.is_in_transaction(self.appid, 1))

    # and when it's blacklisted
    zk.ZKTransaction.should_receive('is_blacklisted').and_return(True)
    fake_transaction = zk.ZKTransaction(host="something", start_gc=False)
    self.assertRaises(zk.ZKTransactionException, transaction.is_in_transaction,
      self.appid, 1)
Example #27
0
  def test_check_transaction(self):
    # mock out getTransactionRootPath
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('get_transaction_prefix_path').with_args(
      self.appid).and_return('/rootpath')
    zk.ZKTransaction.should_receive('is_blacklisted').and_return(False)
    
    # mock out initializing a ZK connection
    fake_zookeeper = flexmock(name='fake_zoo')
    fake_zookeeper.should_receive('start')
    fake_zookeeper.should_receive('exists').and_return(True)

    flexmock(kazoo.client)
    kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)

    transaction = zk.ZKTransaction(host="something", start_gc=False)
    self.assertEquals(True, transaction.check_transaction(self.appid, 1))

    # Check to make sure it raises exception for blacklisted transactions.
    zk.ZKTransaction.should_receive('is_blacklisted').and_return(True)
    self.assertRaises(zk.ZKTransactionException, transaction.check_transaction,
      self.appid, 1)

    zk.ZKTransaction.should_receive('is_blacklisted').and_return(False)
    fake_zookeeper.should_receive('exists').and_return(False)
    self.assertRaises(zk.ZKTransactionException, transaction.check_transaction,
      self.appid, 1)
 def test_create_java_app_env(self):
   app_name = 'foo'
   flexmock(app_manager_server).should_receive('find_web_xml').and_return()
   flexmock(app_manager_server).should_receive('extract_env_vars_from_xml').\
     and_return({})
   env_vars = app_manager_server.create_java_app_env(app_name)
   assert 'appscale' in env_vars['APPSCALE_HOME']
Example #29
0
  def testTailWithIndexInBounds(self):
    # calling 'appscale tail 1 *' should tail from the second node
    # (nodes[1]). If there are two nodes in this deployment,
    # we should tail from it successfully
    appscale = AppScale()

    contents = { 'keyname' : 'boo' }
    yaml_dumped_contents = yaml.dump(contents)

    one = {
      'public_ip' : 'blarg'
    }
    two = {
      'public_ip' : 'blarg2'
    }
    nodes = {'node_info': [one, two]}
    nodes_contents = json.dumps(nodes)

    mock = self.addMockForAppScalefile(appscale, yaml_dumped_contents)
    (mock.should_receive('open')
      .with_args(appscale.get_locations_json_file('boo'))
      .and_return(flexmock(read=lambda: nodes_contents)))

    flexmock(subprocess)
    subprocess.should_receive('call').with_args(["ssh", "-o",
      "StrictHostkeyChecking=no", "-i", appscale.get_key_location('boo'),
      "root@blarg2", "tail -F /var/log/appscale/c*"]).and_return().once()
    appscale.tail(1, "c*")
  def test_upload_app_with_non_alpha_appid(self):
    # we only support four runtimes - abort if the user gives us an unsupported
    # one

    # add in mocks so that there is an app.yaml, but with no appid set
    flexmock(os.path)
    os.path.should_call('exists')
    app_yaml_location = AppEngineHelper.get_app_yaml_location(self.app_dir)
    os.path.should_receive('exists').with_args(app_yaml_location) \
      .and_return(True)

    # mock out reading the app.yaml file
    builtins = flexmock(sys.modules['__builtin__'])
    builtins.should_call('open')  # set the fall-through

    fake_app_yaml = flexmock(name="fake_app_yaml")
    fake_app_yaml.should_receive('read').and_return(yaml.dump({
      'application' : 'baz*',
      'runtime' : 'python'
    }))
    builtins.should_receive('open').with_args(app_yaml_location, 'r') \
      .and_return(fake_app_yaml)

    argv = [
      "--keyname", self.keyname,
      "--file", self.app_dir
    ]
    options = ParseArgs(argv, self.function).args
    self.assertRaises(AppEngineConfigException, AppScaleTools.upload_app, options)
 def __init__(self, tmpdir):
     self.dockerfile_path = str(tmpdir.join('Dockerfile'))
     self.path = str(tmpdir)
     self.commit_id = None
     self.config = flexmock(autorebuild=dict(from_latest=False))
  def setupServerStatusMocks(self):
    fake_key1 = flexmock(name='key1', id=lambda: '1.1.1.1')
    fake_server1 = flexmock(name='ServerStatus', ip='1.1.1.1', cpu='25',
      memory='50', disk='100', roles='roles2', key=fake_key1)
    fake_server1.should_receive('put').and_return()

    fake_key2 = flexmock(name='key1', id=lambda: '2.2.2.2')
    fake_server2 = flexmock(name='ServerStatus', ip='2.2.2.2', cpu='75',
      memory='55', disk='100', roles='roles2', key=fake_key2)
    fake_server2.should_receive('put').and_return()

    flexmock(app_dashboard_data).should_receive('ServerStatus') \
      .and_return(fake_server1)
    fake_server_q = flexmock()
    fake_server_q.should_receive('get') \
      .and_return(fake_server1) \
      .and_return(fake_server2)
    flexmock(AppDashboardData).should_receive('get_all') \
      .with_args(app_dashboard_data.ServerStatus)\
      .and_return([fake_server1, fake_server2])
    flexmock(AppDashboardData).should_receive('get_by_id') \
      .with_args(app_dashboard_data.ServerStatus, re.compile('\d')) \
      .and_return(fake_server1) \
      .and_return(fake_server2)
  def test_update_users(self):
    flexmock(AppDashboardHelper).should_receive('list_all_users')\
      .and_return(['*****@*****.**', '*****@*****.**', '*****@*****.**']).once()
    flexmock(AppDashboardHelper).should_receive('is_user_cloud_admin')\
      .with_args('*****@*****.**').and_return(True).once()
    flexmock(AppDashboardHelper).should_receive('is_user_cloud_admin')\
      .with_args('*****@*****.**').and_return(False).once()
    flexmock(AppDashboardHelper).should_receive('is_user_cloud_admin')\
      .with_args('*****@*****.**').and_return(False).once()

    flexmock(AppDashboardHelper).should_receive('can_upload_apps')\
      .with_args('*****@*****.**').and_return(True).once()
    flexmock(AppDashboardHelper).should_receive('can_upload_apps')\
      .with_args('*****@*****.**').and_return(True).once()
    flexmock(AppDashboardHelper).should_receive('can_upload_apps')\
      .with_args('*****@*****.**').and_return(False).once()

    flexmock(AppDashboardHelper).should_receive('get_owned_apps')\
      .with_args('*****@*****.**').and_return(['app1', 'app2']).once()
    flexmock(AppDashboardHelper).should_receive('get_owned_apps')\
      .with_args('*****@*****.**').and_return(['app2']).once()
    flexmock(AppDashboardHelper).should_receive('get_owned_apps')\
      .with_args('*****@*****.**').and_return(['app2']).once()

    self.setupUserInfoMocks()

    data1 = AppDashboardData()
    output = data1.update_users()
    self.assertEquals(len(output), 3)
    self.assertTrue(output[0].is_user_cloud_admin)
    self.assertFalse(output[1].is_user_cloud_admin)
    self.assertFalse(output[2].is_user_cloud_admin)
    self.assertTrue(output[0].can_upload_apps)
    self.assertTrue(output[1].can_upload_apps)
    self.assertFalse(output[2].can_upload_apps)
 def test_update_database_info(self):
   fake_get_appcontroller_client = flexmock()
   data = AppDashboardData()
   output = data.update_database_info()
   self.assertEquals(output['table'], 'table')
   self.assertEquals(output['replication'], 3)
 def test_init(self):
   data1 = AppDashboardData()
   self.assertNotEquals(None, data1.helper)
   
   data2 = AppDashboardData(flexmock())
   self.assertNotEquals(None, data2.helper)
 def setupUsersAPIMocks(self):
   flexmock(users)
   users.should_receive('get_current_user').and_return(None) \
     .and_return(flexmock(email=lambda:'*****@*****.**')) \
     .and_return(flexmock(email=lambda:'*****@*****.**')) \
     .and_return(flexmock(email=lambda:'*****@*****.**'))
 def setupFakePutsAndDeletes(self):
   flexmock(ndb).should_receive('put_multi').and_return()
   flexmock(ndb).should_receive('delete_multi').and_return()
Example #38
0
    def test_invalid_conference_returns_none(self, *args, **kwargs):
        team_conference = {
            'florida-state': 'acc',
            'boston-college': 'acc',
            'clemson': 'acc',
            'north-carolina-state': 'acc',
            'syracuse': 'acc',
            'wake-forest': 'acc',
            'louisville': 'acc',
            'virginia-tech': 'acc',
            'duke': 'acc',
            'georgia-tech': 'acc',
            'pittsburgh': 'acc',
            'virginia': 'acc',
            'miami-fl': 'acc',
            'north-carolina': 'acc',
            'florida': 'sec',
            'georgia': 'sec',
            'kentucky': 'sec',
            'missouri': 'sec',
            'south-carolina': 'sec',
            'vanderbilt': 'sec',
            'tennessee': 'sec',
            'alabama': 'sec',
            'arkansas': 'sec',
            'auburn': 'sec',
            'louisiana-state': 'sec',
            'mississippi-state': 'sec',
            'mississippi': 'sec',
            'texas-am': 'sec',
            'buffalo': 'mac',
            'ohio': 'mac',
            'bowling-green-state': 'mac',
            'kent-state': 'mac',
            'miami-oh': 'mac',
            'akron': 'mac',
            'ball-state': 'mac',
            'eastern-michigan': 'mac',
            'toledo': 'mac',
            'central-michigan': 'mac',
            'northern-illinois': 'mac',
            'western-michigan': 'mac',
            'georgia-southern': 'sun-belt',
            'appalachian-state': 'sun-belt',
            'coastal-carolina': 'sun-belt',
            'arkansas-state': 'sun-belt',
            'georgia-state': 'sun-belt',
            'louisiana-lafayette': 'sun-belt',
            'louisiana-monroe': 'sun-belt',
            'south-alabama': 'sun-belt',
            'texas-state': 'sun-belt',
            'troy': 'sun-belt',
            'idaho': 'sun-belt',
            'baylor': 'big-12',
            'kansas-state': 'big-12',
            'oklahoma': 'big-12',
            'oklahoma-state': 'big-12',
            'texas-christian': 'big-12',
            'west-virginia': 'big-12',
            'kansas': 'big-12',
            'texas': 'big-12',
            'texas-tech': 'big-12',
            'iowa-state': 'big-12',
            'colorado-state': 'mwc',
            'air-force': 'mwc',
            'boise-state': 'mwc',
            'new-mexico': 'mwc',
            'wyoming': 'mwc',
            'utah-state': 'mwc',
            'hawaii': 'mwc',
            'fresno-state': 'mwc',
            'nevada': 'mwc',
            'nevada-las-vegas': 'mwc',
            'san-diego-state': 'mwc',
            'san-jose-state': 'mwc',
            'california': 'pac-12',
            'oregon': 'pac-12',
            'stanford': 'pac-12',
            'washington-state': 'pac-12',
            'oregon-state': 'pac-12',
            'washington': 'pac-12',
            'arizona-state': 'pac-12',
            'colorado': 'pac-12',
            'southern-california': 'pac-12',
            'utah': 'pac-12',
            'arizona': 'pac-12',
            'ucla': 'pac-12',
            'central-florida': 'american',
            'connecticut': 'american',
            'cincinnati': 'american',
            'south-florida': 'american',
            'east-carolina': 'american',
            'temple': 'american',
            'houston': 'american',
            'memphis': 'american',
            'tulsa': 'american',
            'navy': 'american',
            'southern-methodist': 'american',
            'tulane': 'american',
            'charlotte': 'cusa',
            'marshall': 'cusa',
            'florida-atlantic': 'cusa',
            'florida-international': 'cusa',
            'middle-tennessee-state': 'cusa',
            'old-dominion': 'cusa',
            'western-kentucky': 'cusa',
            'louisiana-tech': 'cusa',
            'north-texas': 'cusa',
            'southern-mississippi': 'cusa',
            'alabama-birmingham': 'cusa',
            'rice': 'cusa',
            'texas-el-paso': 'cusa',
            'texas-san-antonio': 'cusa',
            'liberty': 'independent',
            'massachusetts': 'independent',
            'new-mexico-state': 'independent',
            'brigham-young': 'independent',
            'notre-dame': 'independent',
            'army': 'independent'
        }

        flexmock(utils) \
            .should_receive('_todays_date') \
            .and_return(MockDateTime(YEAR, MONTH))
        flexmock(Conferences) \
            .should_receive('_find_conferences') \
            .and_return(None)
        flexmock(Conferences) \
            .should_receive('team_conference') \
            .and_return(team_conference)

        big_ten_schools = [
            'indiana', 'maryland', 'michigan-state', 'ohio-state',
            'penn-state', 'rutgers', 'michigan', 'northwestern', 'purdue',
            'illinois', 'iowa', 'minnesota', 'wisconsin', 'nebraska'
        ]

        teams = Teams()

        for team in big_ten_schools:
            assert teams(team).conference is None
Example #39
0
    def setUp(self):
        # Set our test scenario differently from the default; must be BEFORE
        # the super call.
        self.scenario_dict = dict(
            name='Master Test Scenario - ablkei',
            sizes=[
                dict(name='tiny', size_min=99, size_max=100),
                dict(name='small',
                     size_min=1990,
                     size_max=1990,
                     crud_profile=[71, 9, 12, 8]),
                dict(name='medium', size_min=2990, size_max=3000),
                dict(name='unused', size_min=9876543, size_max=9876543),
                dict(name='large',
                     size_min=399000,
                     size_max=400000,
                     crud_profile=[16, 61, 7, 16]),
                dict(name='huge', size_min=49900000, size_max=71499999)
            ],
            initial_files=dict(
                tiny=300,
                small=400,
                medium=500,
                large=200,
                huge=70,
            ),
            operation_count=5000,
            #             C  R  U  D
            crud_profile=[5, 3, 1, 1],
            user_count=2,
        )
        super(TestMaster, self).setUp()

        self.zmq_host = 'slick.queue.com'
        self.zmq_work_port = 7482
        self.zmq_results_port = 18398
        self.work_endpoint = 'tcp://%s:%d' % (self.zmq_host,
                                              self.zmq_work_port)
        self.results_endpoint = 'tcp://%s:%d' % (self.zmq_host,
                                                 self.zmq_results_port)

        self.mock_context = flexmock()
        flexmock(zmq.Context).new_instances(self.mock_context).once

        self.mock_work_push = flexmock(send=self._send)
        self.mock_context.should_receive('socket').with_args(
            zmq.PUSH, ).and_return(self.mock_work_push).once
        self.mock_work_push.should_receive('bind').with_args(
            self.work_endpoint, ).once

        self.mock_results_pull = flexmock(recv=self._recv)
        self.mock_context.should_receive('socket').with_args(
            zmq.PULL, ).and_return(self.mock_results_pull).once
        self.mock_results_pull.should_receive('bind').with_args(
            self.results_endpoint, ).once

        self.master = Master(self.zmq_host,
                             self.zmq_work_port,
                             self.zmq_results_port,
                             connect_timeout=3.14159,
                             network_timeout=2.71828)

        self._send_calls = []
        self._recv_returns = []
Example #40
0
    def setup_method(self, *args, **kwargs):
        self.results = {
            'conference': 'big-ten',
            'abbreviation': 'PURDUE',
            'name': 'Purdue',
            'games': 13,
            'wins': 7,
            'losses': 6,
            'win_percentage': .538,
            'conference_wins': 4,
            'conference_losses': 5,
            'conference_win_percentage': .444,
            'points_per_game': 25.2,
            'points_against_per_game': 20.5,
            'strength_of_schedule': 6.21,
            'simple_rating_system': 9.74,
            'pass_completions': 22.5,
            'pass_attempts': 37.8,
            'pass_completion_percentage': 59.5,
            'pass_yards': 251.5,
            'interceptions': 0.8,
            'pass_touchdowns': 2.1,
            'rush_attempts': 34.4,
            'rush_yards': 151.5,
            'rush_yards_per_attempt': 4.4,
            'rush_touchdowns': 0.9,
            'plays': 72.2,
            'yards': 403.1,
            'turnovers': 1.3,
            'fumbles_lost': 0.5,
            'yards_per_play': 5.6,
            'pass_first_downs': 11.1,
            'rush_first_downs': 8.8,
            'first_downs_from_penalties': 1.8,
            'first_downs': 21.7,
            'penalties': 5.9,
            'yards_from_penalties': 50.6,
            'opponents_pass_completions': 19.1,
            'opponents_pass_attempts': 33.6,
            'opponents_pass_completion_percentage': 56.8,
            'opponents_pass_yards': 242.5,
            'opponents_interceptions': 0.8,
            'opponents_pass_touchdowns': 1.6,
            'opponents_rush_attempts': 37.4,
            'opponents_rush_yards': 133.2,
            'opponents_rush_yards_per_attempt': 3.6,
            'opponents_rush_touchdowns': 0.8,
            'opponents_plays': 71.0,
            'opponents_yards': 375.8,
            'opponents_turnovers': 1.6,
            'opponents_fumbles_lost': 0.8,
            'opponents_yards_per_play': 5.3,
            'opponents_pass_first_downs': 10.6,
            'opponents_rush_first_downs': 6.8,
            'opponents_first_downs_from_penalties': 1.8,
            'opponents_first_downs': 19.2,
            'opponents_penalties': 6.9,
            'opponents_yards_from_penalties': 59.8
        }
        self.schools = [
            'UCF', 'Memphis', 'Oklahoma', 'Oklahoma State', 'Arizona',
            'Ohio State', 'Penn State', 'Florida Atlantic', 'Ohio',
            'South Florida', 'Louisville', 'Arkansas State', 'SMU', 'Missouri',
            'Alabama', 'Toledo', 'Washington', 'Oregon', 'North Texas',
            'Georgia', 'Wake Forest', 'West Virginia', 'Texas Tech',
            'Notre Dame', 'Auburn', 'Louisiana-Monroe', 'Western Michigan',
            'Wisconsin', 'Texas Christian', 'Appalachian State',
            'Colorado State', 'Clemson', 'Ole Miss', 'Texas A&M', 'USC',
            'Boise State', 'UCLA', 'Stanford', 'Kansas State',
            'North Carolina State', 'Mississippi State', 'Arizona State',
            'Troy', 'Air Force', 'San Diego State', 'Army', 'Massachusetts',
            'Louisiana Tech', 'Navy', 'Washington State', 'Utah State',
            'Texas', 'Utah', 'New Mexico State', 'Tulsa', 'Iowa State',
            'Northwestern', 'Southern Mississippi', 'Miami (FL)',
            'Northern Illinois', 'Arkansas', 'Nevada-Las Vegas', 'Buffalo',
            'Central Michigan', 'Houston', 'Iowa', 'Louisiana', 'Nevada',
            'Virginia Tech', 'Georgia Tech', 'California', 'Florida State',
            'UAB', 'Tulane', 'Syracuse', 'LSU', 'Fresno State', 'Indiana',
            'Marshall', 'Duke', 'Colorado', 'Eastern Michigan',
            'North Carolina', 'Nebraska', 'Boston College',
            'Florida International', 'Kentucky', 'Middle Tennessee State',
            'Western Kentucky', 'Bowling Green State', 'Michigan', 'Purdue',
            'Temple', 'East Carolina', 'Vanderbilt', 'Michigan State',
            'Miami (OH)', 'Baylor', 'South Carolina', 'Maryland', 'Pitt',
            'Coastal Carolina', 'Connecticut', 'UTSA', 'Wyoming', 'Hawaii',
            'Virginia', 'Akron', 'Florida', 'Minnesota', 'Cincinnati', 'Idaho',
            'Georgia Southern', 'New Mexico', 'Old Dominion', 'Oregon State',
            'Georgia State', 'South Alabama', 'Tennessee', 'Kansas', 'Rutgers',
            'Ball State', 'Texas State', 'Brigham Young', 'Rice',
            'San Jose State', 'Illinois', 'Charlotte', 'Kent State', 'UTEP'
        ]

        team_conference = {
            'florida-state': 'acc',
            'boston-college': 'acc',
            'clemson': 'acc',
            'north-carolina-state': 'acc',
            'syracuse': 'acc',
            'wake-forest': 'acc',
            'louisville': 'acc',
            'virginia-tech': 'acc',
            'duke': 'acc',
            'georgia-tech': 'acc',
            'pittsburgh': 'acc',
            'virginia': 'acc',
            'miami-fl': 'acc',
            'north-carolina': 'acc',
            'florida': 'sec',
            'georgia': 'sec',
            'kentucky': 'sec',
            'missouri': 'sec',
            'south-carolina': 'sec',
            'vanderbilt': 'sec',
            'tennessee': 'sec',
            'alabama': 'sec',
            'arkansas': 'sec',
            'auburn': 'sec',
            'louisiana-state': 'sec',
            'mississippi-state': 'sec',
            'mississippi': 'sec',
            'texas-am': 'sec',
            'buffalo': 'mac',
            'ohio': 'mac',
            'bowling-green-state': 'mac',
            'kent-state': 'mac',
            'miami-oh': 'mac',
            'akron': 'mac',
            'ball-state': 'mac',
            'eastern-michigan': 'mac',
            'toledo': 'mac',
            'central-michigan': 'mac',
            'northern-illinois': 'mac',
            'western-michigan': 'mac',
            'georgia-southern': 'sun-belt',
            'appalachian-state': 'sun-belt',
            'coastal-carolina': 'sun-belt',
            'arkansas-state': 'sun-belt',
            'georgia-state': 'sun-belt',
            'louisiana-lafayette': 'sun-belt',
            'louisiana-monroe': 'sun-belt',
            'south-alabama': 'sun-belt',
            'texas-state': 'sun-belt',
            'troy': 'sun-belt',
            'idaho': 'sun-belt',
            'baylor': 'big-12',
            'kansas-state': 'big-12',
            'oklahoma': 'big-12',
            'oklahoma-state': 'big-12',
            'texas-christian': 'big-12',
            'west-virginia': 'big-12',
            'kansas': 'big-12',
            'texas': 'big-12',
            'texas-tech': 'big-12',
            'iowa-state': 'big-12',
            'colorado-state': 'mwc',
            'air-force': 'mwc',
            'boise-state': 'mwc',
            'new-mexico': 'mwc',
            'wyoming': 'mwc',
            'utah-state': 'mwc',
            'hawaii': 'mwc',
            'fresno-state': 'mwc',
            'nevada': 'mwc',
            'nevada-las-vegas': 'mwc',
            'san-diego-state': 'mwc',
            'san-jose-state': 'mwc',
            'california': 'pac-12',
            'oregon': 'pac-12',
            'stanford': 'pac-12',
            'washington-state': 'pac-12',
            'oregon-state': 'pac-12',
            'washington': 'pac-12',
            'arizona-state': 'pac-12',
            'colorado': 'pac-12',
            'southern-california': 'pac-12',
            'utah': 'pac-12',
            'arizona': 'pac-12',
            'ucla': 'pac-12',
            'central-florida': 'american',
            'connecticut': 'american',
            'cincinnati': 'american',
            'south-florida': 'american',
            'east-carolina': 'american',
            'temple': 'american',
            'houston': 'american',
            'memphis': 'american',
            'tulsa': 'american',
            'navy': 'american',
            'southern-methodist': 'american',
            'tulane': 'american',
            'charlotte': 'cusa',
            'marshall': 'cusa',
            'florida-atlantic': 'cusa',
            'florida-international': 'cusa',
            'middle-tennessee-state': 'cusa',
            'old-dominion': 'cusa',
            'western-kentucky': 'cusa',
            'louisiana-tech': 'cusa',
            'north-texas': 'cusa',
            'southern-mississippi': 'cusa',
            'alabama-birmingham': 'cusa',
            'rice': 'cusa',
            'texas-el-paso': 'cusa',
            'texas-san-antonio': 'cusa',
            'liberty': 'independent',
            'massachusetts': 'independent',
            'new-mexico-state': 'independent',
            'brigham-young': 'independent',
            'notre-dame': 'independent',
            'army': 'independent',
            'indiana': 'big-ten',
            'maryland': 'big-ten',
            'michigan-state': 'big-ten',
            'ohio-state': 'big-ten',
            'penn-state': 'big-ten',
            'rutgers': 'big-ten',
            'michigan': 'big-ten',
            'northwestern': 'big-ten',
            'purdue': 'big-ten',
            'illinois': 'big-ten',
            'iowa': 'big-ten',
            'minnesota': 'big-ten',
            'wisconsin': 'big-ten',
            'nebraska': 'big-ten'
        }
        self.team_conference = team_conference

        flexmock(utils) \
            .should_receive('_todays_date') \
            .and_return(MockDateTime(YEAR, MONTH))
        flexmock(Conferences) \
            .should_receive('_find_conferences') \
            .and_return(None)
        flexmock(Conferences) \
            .should_receive('team_conference') \
            .and_return(team_conference)

        self.teams = Teams()
Example #41
0
def test_allowed_gpg_keys_none(api_instance_source_git: PackitAPI):
    api_instance_source_git.up.allowed_gpg_keys = None
    flexmock(CommitVerifier).should_receive("check_signature_of_commit").times(0)
    api_instance_source_git.up.check_last_commit()
Example #42
0
def insert_subprocess_mock(check_call_command, **kwargs):
    subprocess = flexmock(module.subprocess)
    subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
    def test_run_build(
        self, x86_task_params, x86_build_dir, mock_podman_remote, mock_locked_resource, caplog,
            fail_image_size_check, is_flatpak
    ):
        mock_workflow_data(enabled_platforms=["x86_64"])
        if fail_image_size_check:
            mock_config(REGISTRY_CONFIG, REMOTE_HOST_CONFIG, image_size_limit=1233)
        else:
            mock_config(REGISTRY_CONFIG, REMOTE_HOST_CONFIG, image_size_limit=1234)
        x86_build_dir.dockerfile_path.write_text(DOCKERFILE_CONTENT)

        def mock_build_container(*, build_dir, build_args, dest_tag, squash_all):
            assert build_dir.path == x86_build_dir.path
            assert build_dir.platform == "x86_64"
            assert build_args == BUILD_ARGS
            assert dest_tag == X86_UNIQUE_IMAGE
            assert squash_all == is_flatpak

            yield from ["output line 1\n", "output line 2\n"]

        (
            flexmock(mock_podman_remote)
            .should_receive("build_container")
            .once()
            .replace_with(mock_build_container)
        )
        (
            flexmock(mock_podman_remote)
            .should_receive("push_container")
            .with_args(X86_UNIQUE_IMAGE, insecure=REGISTRY_CONFIG[0]["insecure"])
            .times(0 if fail_image_size_check else 1)
        )
        (
            flexmock(mock_podman_remote)
            .should_receive("get_image_size")
            .with_args(X86_UNIQUE_IMAGE)
            .and_return(1234)
            .once()
        )

        flexmock(mock_locked_resource).should_receive("unlock").once()

        x86_task_params.user_params['flatpak'] = is_flatpak

        task = BinaryBuildTask(x86_task_params)
        if fail_image_size_check:
            err_msg = 'The size 1234 of image registry.example.org/osbs/spam:v1.0-x86_64 exceeds ' \
                      'the limitation 1233 configured in reactor config.'
            with pytest.raises(ExceedsImageSizeError, match=err_msg):
                task.execute()
        else:
            task.execute()

        assert (
            f"Building for the x86_64 platform from {x86_build_dir.dockerfile_path}" in caplog.text
        )
        assert "output line 1" in caplog.text
        assert "output line 2" in caplog.text
        assert DOCKERFILE_CONTENT in caplog.text

        build_log_file = Path(x86_task_params.context_dir, 'x86_64-build.log')
        assert build_log_file.exists()
        build_logs = build_log_file.read_text().splitlines()
        assert ["output line 1", "output line 2"] == build_logs
Example #44
0
    def test_run_scenario_only_doable_job_should_pass(self):
        def not_doable_jobs():
            yield dict(
                type=ssbench.CREATE_OBJECT,
                size_str='small',
                test_id=0,
            )
            yield dict(
                type=ssbench.READ_OBJECT,
                size_str='small',
                test_id=1,
            )

        # make the scenario returns not doable jobs sequence
        self.scenario = flexmock(self.scenario)
        self.scenario \
            .should_receive('bench_jobs') \
            .replace_with(not_doable_jobs)
        # make the scenario return no init jobs
        self.scenario \
            .should_receive('initial_jobs') \
            .replace_with(lambda: [])

        # make clinet not to send a real request
        mock_client = flexmock(client)
        mock_client \
            .should_receive('head_container')

        bench_jobs = list(self.scenario.bench_jobs())

        def mock_result(**kwargs):
            job_result = dict(
                type=ssbench.READ_OBJECT,
                size_str='small',
                container='container',
                name='john.smith',
                first_byte_latency=0,
            )
            job_result.update(kwargs)
            return job_result

        # the first create object result will let RunState put it in queue
        recvs = [[mock_result(type=ssbench.CREATE_OBJECT)]] + \
            [[mock_result()] for i in range(len(bench_jobs))]
        self._recv_returns = map(msgpack.dumps, recvs)

        # run the scenario
        auth_kwargs = dict(
            token='MOCK_TOKEN',
            storage_urls=['http://127.0.0.1:8080/auth/v1.0'],
        )

        orig_stderr = sys.stderr
        sys.stderr = open('/dev/null', 'wb')

        try:
            self.master.run_scenario(self.scenario,
                                     auth_kwargs=auth_kwargs,
                                     run_results=None,
                                     batch_size=2)
        finally:
            sys.stderr = orig_stderr

        sent_jobs = map(msgpack.loads, self._send_calls)
        sent_jobs = sum(sent_jobs, [])  # flatten the list

        # As the sequence is
        #     Batch 1.
        #         Create -> doable
        #         Read -> not doable
        # only doable jobs should be passed to the worker

        # There is a bug which allows non-doable job to be passed
        # into send job queue as None, we are here to make sure
        # None doesn't exist in the sent_jobs
        self.assertNotIn(None, sent_jobs)
Example #45
0
    def setup_method(self, *args, **kwargs):
        flexmock(Game) \
            .should_receive('_parse_game_data') \
            .and_return(None)

        self.game = Game(None)
 def mock_which_podman(self):
     which_podman.cache_clear()
     flexmock(shutil).should_receive("which").with_args("podman").and_return("/usr/bin/podman")
Example #47
0
    def test_acquire_lock(self):
        # mock out waitForConnect
        flexmock(zk.ZKTransaction)
        zk.ZKTransaction.should_receive('get_lock_root_path').\
           and_return('/lock/root/path')
        zk.ZKTransaction.should_receive('get_transaction_prefix_path').\
           and_return('/rootpath/' + self.appid)
        fake_zookeeper = flexmock(name='fake_zoo',
                                  get='get',
                                  connected=lambda: True)
        fake_zookeeper.should_receive('start')
        fake_zookeeper.should_receive('retry')

        flexmock(kazoo.client)
        kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)

        # first, test out getting a lock for a regular transaction, that we don't
        # already have the lock for
        zk.ZKTransaction.should_receive('is_in_transaction').and_return(False)
        zk.ZKTransaction.should_receive('acquire_additional_lock').and_return(
            True)

        transaction = zk.ZKTransaction(host="something")
        self.assertEquals(
            True, transaction.acquire_lock(self.appid, "txid", "somekey"))

        # next, test when we're in a transaction and we already have the lock
        zk.ZKTransaction.should_receive('is_in_transaction').and_return(True)
        zk.ZKTransaction.should_receive('get_transaction_lock_list_path').\
           and_return('/rootpath/' + self.appid + "/tx1")
        fake_zookeeper.should_receive('retry').with_args('get', str) \
          .and_return(['/lock/root/path'])

        transaction = zk.ZKTransaction(host="something")
        self.assertEquals(
            True, transaction.acquire_lock(self.appid, "txid", "somekey"))

        # next, test when we're in a non-XG transaction and we're not in the lock
        # root path
        zk.ZKTransaction.should_receive('is_in_transaction').and_return(True)
        zk.ZKTransaction.should_receive('get_transaction_lock_list_path').\
           and_return('/rootpath/' + self.appid + "/tx1")
        fake_zookeeper.should_receive('retry').with_args('get', str) \
          .and_return(['/lock/root/path2'])
        zk.ZKTransaction.should_receive('is_xg').and_return(False)

        transaction = zk.ZKTransaction(host="something")
        self.assertRaises(zk.ZKTransactionException, transaction.acquire_lock,
                          self.appid, "txid", "somekey")

        # next, test when we're in a XG transaction and we're not in the lock
        # root path
        zk.ZKTransaction.should_receive('is_in_transaction').and_return(True)
        zk.ZKTransaction.should_receive('get_transaction_lock_list_path').\
           and_return('/rootpath/' + self.appid + "/tx1")
        fake_zookeeper.should_receive('retry').with_args('get', str) \
          .and_return(['/lock/root/path2'])
        zk.ZKTransaction.should_receive('is_xg').and_return(True)

        transaction = zk.ZKTransaction(host="something")
        self.assertEquals(
            True, transaction.acquire_lock(self.appid, "txid", "somekey"))
Example #48
0
def no_s3_connection():
    """Mock the connection to S3."""
    flexmock(AmazonS3).should_receive('is_connected').and_return(True)
  def test_dynamic_delete(self):
    del_request = flexmock()
    del_request.should_receive("key_list")
    del_request.should_receive("has_transaction").never()
    del_request.should_receive("transaction").never()
    dd = DatastoreDistributed(None, None)
    dd.dynamic_delete("appid", del_request)

    fake_element = flexmock()
    fake_element.should_receive("type").and_return("kind")
    fake_path = flexmock()
    fake_path.should_receive("element_list").and_return([fake_element])
    fake_key = flexmock()
    fake_key.should_receive("path").and_return(fake_path)

    del_request = flexmock()
    del_request.should_receive("key_list").and_return([fake_key])
    del_request.should_receive("has_transaction").and_return(True).twice()
    transaction = flexmock()
    transaction.should_receive("handle").and_return(1)
    del_request.should_receive("transaction").and_return(transaction).once()
    del_request.should_receive("has_mark_changes").and_return(False)
    dd = DatastoreDistributed(None, None)
    flexmock(dd).should_receive("acquire_locks_for_trans").and_return({})
    flexmock(dd).should_receive("release_locks_for_nontrans").never()
    flexmock(dd).should_receive("delete_entities").once()
    flexmock(dd).should_receive("get_entity_kind").and_return("kind")
    dd.dynamic_delete("appid", del_request)

    del_request = flexmock()
    del_request.should_receive("key_list").and_return([fake_key])
    del_request.should_receive("has_transaction").and_return(False).twice()
    del_request.should_receive("has_mark_changes").and_return(False)
    dd = DatastoreDistributed(None, None)
    flexmock(dd).should_receive("acquire_locks_for_trans").never()
    flexmock(dd).should_receive("acquire_locks_for_nontrans").once().and_return({})
    flexmock(dd).should_receive("delete_entities").once()
    flexmock(dd).should_receive("release_locks_for_nontrans").once()
    dd.dynamic_delete("appid", del_request)
Example #50
0
    def test_acquire_additional_lock(self):
        # mock out waitForConnect
        flexmock(zk.ZKTransaction)
        zk.ZKTransaction.should_receive('check_transaction')
        zk.ZKTransaction.should_receive('get_transaction_path').\
           and_return('/txn/path')
        zk.ZKTransaction.should_receive('get_lock_root_path').\
           and_return('/lock/root/path')
        zk.ZKTransaction.should_receive('get_transaction_prefix_path').\
           and_return('/rootpath/' + self.appid)

        fake_zookeeper = flexmock(name='fake_zoo',
                                  create='create',
                                  create_async='create_async',
                                  get='get',
                                  set_async='set_async',
                                  connected=lambda: True)
        fake_zookeeper.should_receive('start')
        fake_zookeeper.should_receive('retry').with_args(
            'create',
            str,
            makepath=bool,
            sequence=bool,
            ephemeral=bool,
            value=str,
            acl=None).and_return("/some/lock/path")
        fake_zookeeper.should_receive('retry').with_args('create_async',
                                                         str,
                                                         value=str,
                                                         acl=None,
                                                         ephemeral=bool,
                                                         makepath=bool,
                                                         sequence=bool)
        fake_zookeeper.should_receive('retry').with_args('create_async',
                                                         str,
                                                         value=str,
                                                         acl=str,
                                                         ephemeral=bool,
                                                         makepath=bool,
                                                         sequence=bool)
        lock_list = ['path1', 'path2', 'path3']
        lock_list_str = zk.LOCK_LIST_SEPARATOR.join(lock_list)
        fake_zookeeper.should_receive('retry').with_args('get', str) \
          .and_return([lock_list_str])
        fake_zookeeper.should_receive('retry').with_args('set_async', str, str)

        flexmock(kazoo.client)
        kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)

        transaction = zk.ZKTransaction(host="something")
        self.assertEquals(
            True,
            transaction.acquire_additional_lock(self.appid, "txid", "somekey",
                                                False))

        # Test for when we want to create a new ZK node for the lock path
        self.assertEquals(
            True,
            transaction.acquire_additional_lock(self.appid, "txid", "somekey",
                                                True))

        # Test for existing max groups
        lock_list = ['path' + str(num + 1) for num in range(MAX_GROUPS_FOR_XG)]
        lock_list_str = zk.LOCK_LIST_SEPARATOR.join(lock_list)
        fake_zookeeper.should_receive('retry').with_args('get', str) \
          .and_return([lock_list_str])

        transaction = zk.ZKTransaction(host="something")
        self.assertRaises(zk.ZKTransactionException,
                          transaction.acquire_additional_lock, self.appid,
                          "txid", "somekey", False)

        # Test for when there is a node which already exists.
        fake_zookeeper.should_receive('retry').with_args(
            'create', str, str, None, bool, bool,
            bool).and_raise(kazoo.exceptions.NodeExistsError)
        transaction = zk.ZKTransaction(host="something")
        self.assertRaises(zk.ZKTransactionException,
                          transaction.acquire_additional_lock, self.appid,
                          "txid", "somekey", False)
Example #51
0
 def get_connection(self):
     return flexmock(Connection(None))
  def test_zigzag_merge_join(self):
    zookeeper = flexmock()
    zookeeper.should_receive("get_transaction_id").and_return(1)
    zookeeper.should_receive("get_valid_transaction_id").and_return(1)
    zookeeper.should_receive("register_updated_key").and_return(1)
    zookeeper.should_receive("acquire_lock").and_return(True)
    zookeeper.should_receive("release_lock").and_return(True)
    db_batch = flexmock()
    db_batch.should_receive("batch_delete").and_return(None)
    db_batch.should_receive("batch_put_entity").and_return(None)
    db_batch.should_receive("batch_get_entity").and_return(None)

    query = datastore_pb.Query()
    dd = DatastoreDistributed(db_batch, zookeeper) 
    flexmock(dd).should_receive("is_zigzag_merge_join").and_return(False)
    self.assertEquals(dd.zigzag_merge_join(None, None, None), None)

    filter_info = {"prop1":[(datastore_pb.Query_Filter.EQUAL, "1")],
      "prop2": [(datastore_pb.Query_Filter.EQUAL, "2")]}
    flexmock(query).should_receive("kind").and_return("kind")
    flexmock(dd).should_receive("get_table_prefix").and_return("prefix")
    flexmock(dd).should_receive("__apply_filters").and_return([])
    flexmock(query).should_receive("limit").and_return(1)
    self.assertEquals(dd.zigzag_merge_join(query, filter_info, []), None)
Example #53
0
def test_run_configuration_logs_on_error_hook_error():
    flexmock(module.borg_environment).should_receive('initialize')
    flexmock(module.command).should_receive('execute_hook').and_raise(OSError)
    expected_results = [flexmock(), flexmock()]
    flexmock(module).should_receive('make_error_log_records').and_return(
        expected_results[:1]).and_return(expected_results[1:])
    flexmock(module).should_receive('run_actions').and_raise(OSError)
    config = {'location': {'repositories': ['foo']}}
    arguments = {'global': flexmock(dry_run=False)}

    results = list(module.run_configuration('test.yaml', config, arguments))

    assert results == expected_results
  def test_acquire_locks_for_trans(self):
    dd = DatastoreDistributed(None, None) 
    flexmock(dd).should_receive("is_instance_wrapper").and_return(False).once()
    self.assertRaises(TypeError, dd.acquire_locks_for_trans, [1], 1)

    dd = DatastoreDistributed(None, None) 
    flexmock(dd).should_receive("is_instance_wrapper").and_return(True) \
      .and_return(False).and_return(False)
    self.assertRaises(TypeError, dd.acquire_locks_for_trans, [1], 1)

    dd = DatastoreDistributed(None, None) 
    flexmock(dd).should_receive("is_instance_wrapper").and_return(True) \
      .and_return(True)

    dd = DatastoreDistributed(None, None) 
    flexmock(dd).should_receive("is_instance_wrapper").and_return(True) \
      .and_return(True).and_return(False)
    flexmock(dd).should_receive("get_table_prefix").and_return("prefix").never()
    flexmock(dd).should_receive("get_root_key_from_entity_key").and_return("rootkey").never()
    self.assertEquals({}, dd.acquire_locks_for_trans([], 1))

    zookeeper = flexmock()
    zookeeper.should_receive("acquire_lock").once()
    dd = DatastoreDistributed(None, zookeeper) 
    entity = flexmock()
    entity.should_receive("app").and_return("appid")
    flexmock(dd).should_receive("is_instance_wrapper").and_return(True) \
      .and_return(True).and_return(True)
    flexmock(dd).should_receive("get_root_key_from_entity_key").and_return("rootkey").once()
    self.assertEquals({'rootkey':1}, dd.acquire_locks_for_trans([entity], 1))

    zookeeper = flexmock()
    zookeeper.should_receive("acquire_lock").once().and_raise(ZKTransactionException)
    zookeeper.should_receive("notify_failed_transaction").once()
    dd = DatastoreDistributed(None, zookeeper) 
    entity = flexmock()
    entity.should_receive("app").and_return("appid")
    flexmock(dd).should_receive("is_instance_wrapper").and_return(True) \
      .and_return(True).and_return(True)
    flexmock(dd).should_receive("get_root_key_from_entity_key").and_return("rootkey").once()
    self.assertRaises(ZKTransactionException, dd.acquire_locks_for_trans, [entity], 1)
Example #55
0
 def setUp(self):
     self.switch = Cisco(
         SwitchDescriptor(model='cisco', hostname="my.hostname"))
     SubShell.debug = True
     self.mocked_ssh_client = flexmock()
     self.switch.ssh = self.mocked_ssh_client
Example #56
0
def test_build_srpm_log_format(github_pr_event):
    def mock_packit_log(*args, **kwargs):
        packit_logger = logging.getLogger("packit")
        packit_logger.debug("try debug")
        packit_logger.info("try info")
        return "my.srpm"

    def inspect_log_date_format(logs=None, **_):

        timestamp_reg = re.compile(
            r"[0-9]+-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+\s.*")

        log_lines = 0
        for line in logs.split("\n"):
            logger.debug(line)
            if len(line) == 0:
                continue
            log_lines += 1
            assert timestamp_reg.match(line)

        # Check if both test logs were recorded
        assert log_lines == 2

        return (None, None)

    trigger = flexmock(
        job_config_trigger_type=JobConfigTriggerType.pull_request, id=123)
    flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(
        trigger)
    helper = build_helper(
        event=github_pr_event,
        metadata=JobMetadataConfig(_targets=["bright-future"], scratch=True),
        db_trigger=trigger,
    )

    flexmock(GitProject).should_receive(
        "set_commit_status").and_return().never()
    local_project = flexmock()
    local_project.working_dir = ""
    up = flexmock()
    up.local_project = local_project
    flexmock(PackitAPI).should_receive("up").and_return(up)

    # flexmock(PackitAPI).should_receive("up").and_return()
    flexmock(PackitAPI).should_receive("create_srpm").replace_with(
        mock_packit_log)
    flexmock(SRPMBuildModel).should_receive(
        "create_with_new_run").replace_with(inspect_log_date_format)
    helper._create_srpm()
Example #57
0
def test_workflow_plugin_error(fail_at):
    """
    This is a test for what happens when plugins fail.

    When a prebuild or postbuild plugin fails, and doesn't have
    is_allowed_to_fail=True set, the whole build should fail.
    However, all the exit plugins should run.
    """
    flexmock(DockerfileParser, content='df_content')
    this_file = inspect.getfile(PreRaises)
    mock_docker()
    fake_builder = MockInsideBuilder()
    flexmock(InsideBuilder).new_instances(fake_builder)
    watch_pre = Watcher()
    watch_prepub = Watcher()
    watch_buildstep = Watcher()
    watch_post = Watcher()
    watch_exit = Watcher()
    prebuild_plugins = [{
        'name': 'pre_watched',
        'args': {
            'watcher': watch_pre,
        }
    }]
    buildstep_plugins = [{
        'name': 'buildstep_watched',
        'args': {
            'watcher': watch_buildstep,
        }
    }]
    prepublish_plugins = [{
        'name': 'prepub_watched',
        'args': {
            'watcher': watch_prepub,
        }
    }]
    postbuild_plugins = [{
        'name': 'post_watched',
        'args': {
            'watcher': watch_post
        }
    }]
    exit_plugins = [{'name': 'exit_watched', 'args': {'watcher': watch_exit}}]

    # Insert a failing plugin into one of the build phases
    if fail_at == 'pre_raises':
        prebuild_plugins.insert(0, {'name': fail_at, 'args': {}})
    elif fail_at == 'buildstep_raises':
        buildstep_plugins.insert(0, {'name': fail_at, 'args': {}})
    elif fail_at == 'prepub_raises':
        prepublish_plugins.insert(0, {'name': fail_at, 'args': {}})
    elif fail_at == 'post_raises':
        postbuild_plugins.insert(0, {'name': fail_at, 'args': {}})
    elif fail_at == 'exit_raises' or fail_at == 'exit_raises_allowed':
        exit_plugins.insert(0, {'name': fail_at, 'args': {}})
    else:
        # Typo in the parameter list?
        assert False

    workflow = DockerBuildWorkflow(MOCK_SOURCE,
                                   'test-image',
                                   prebuild_plugins=prebuild_plugins,
                                   buildstep_plugins=buildstep_plugins,
                                   prepublish_plugins=prepublish_plugins,
                                   postbuild_plugins=postbuild_plugins,
                                   exit_plugins=exit_plugins,
                                   plugin_files=[this_file])

    # Most failures cause the build process to abort. Unless, it's
    # an exit plugin that's explicitly allowed to fail.
    if fail_at == 'exit_raises_allowed':
        workflow.build_docker_image()
        assert not workflow.plugins_errors
    else:
        with pytest.raises(PluginFailedException):
            workflow.build_docker_image()

        assert fail_at in workflow.plugins_errors

    # The pre-build phase should only complete if there were no
    # earlier plugin failures.
    assert watch_pre.was_called() == (fail_at != 'pre_raises')

    # The buildstep phase should only complete if there were no
    # earlier plugin failures.
    assert watch_buildstep.was_called() == (fail_at
                                            not in ('pre_raises',
                                                    'buildstep_raises'))

    # The prepublish phase should only complete if there were no
    # earlier plugin failures.
    assert watch_prepub.was_called() == (fail_at
                                         not in ('pre_raises', 'prepub_raises',
                                                 'buildstep_raises'))

    # The post-build phase should only complete if there were no
    # earlier plugin failures.
    assert watch_post.was_called() == (fail_at
                                       not in ('pre_raises', 'prepub_raises',
                                               'buildstep_raises',
                                               'post_raises'))

    # But all exit plugins should run, even if one of them also raises
    # an exception.
    assert watch_exit.was_called()
Example #58
0
def test_run_configuration_executes_hooks_for_create_action():
    flexmock(module.borg_environment).should_receive('initialize')
    flexmock(module.command).should_receive('execute_hook').twice()
    flexmock(module.postgresql).should_receive('dump_databases').once()
    flexmock(module.healthchecks).should_receive('ping_healthchecks').twice()
    flexmock(module.postgresql).should_receive('remove_database_dumps').once()
    flexmock(module).should_receive('run_actions').and_return([])
    config = {'location': {'repositories': ['foo']}}
    arguments = {'global': flexmock(dry_run=False), 'create': flexmock()}

    list(module.run_configuration('test.yaml', config, arguments))
Example #59
0
 def test_version_change_mocked(self):
     """
     version is not not uploaded, so skip in this test
     """
     flexmock(self.api).should_receive("_handle_sources").and_return(None)
     self.check_version_increase()
Example #60
0
def test_cancel_build(request, fail_at):
    """
    Verifies that exit plugins are executed when the build is canceled
    """
    # Make the phase we're testing send us SIGTERM
    phase_signal = defaultdict(lambda: None)
    phase_signal[fail_at] = signal.SIGTERM
    flexmock(DockerfileParser, content='df_content')
    this_file = inspect.getfile(PreRaises)
    mock_docker()
    fake_builder = MockInsideBuilder()
    flexmock(InsideBuilder).new_instances(fake_builder)
    watch_pre = WatcherWithSignal(phase_signal['pre'])
    watch_prepub = WatcherWithSignal(phase_signal['prepub'])
    watch_buildstep = WatcherWithSignal(phase_signal['buildstep'])
    watch_post = WatcherWithSignal(phase_signal['post'])
    watch_exit = WatcherWithSignal(phase_signal['exit'])

    fake_logger = FakeLogger()
    existing_logger = atomic_reactor.plugin.logger

    def restore_logger():
        atomic_reactor.plugin.logger = existing_logger

    request.addfinalizer(restore_logger)
    atomic_reactor.plugin.logger = fake_logger

    workflow = DockerBuildWorkflow(MOCK_SOURCE,
                                   'test-image',
                                   prebuild_plugins=[{
                                       'name': 'pre_watched',
                                       'args': {
                                           'watcher': watch_pre
                                       }
                                   }],
                                   prepublish_plugins=[{
                                       'name': 'prepub_watched',
                                       'args': {
                                           'watcher': watch_prepub,
                                       }
                                   }],
                                   buildstep_plugins=[{
                                       'name': 'buildstep_watched',
                                       'args': {
                                           'watcher': watch_buildstep
                                       }
                                   }],
                                   postbuild_plugins=[{
                                       'name': 'post_watched',
                                       'args': {
                                           'watcher': watch_post
                                       }
                                   }],
                                   exit_plugins=[{
                                       'name': 'exit_watched',
                                       'args': {
                                           'watcher': watch_exit
                                       }
                                   }],
                                   plugin_files=[this_file])
    if fail_at == 'buildstep':
        with pytest.raises(PluginFailedException):
            workflow.build_docker_image()
        assert workflow.build_canceled
        assert ("plugin '%s_watched' raised an exception:" % fail_at +
                " BuildCanceledException('Build was canceled',)",
                ) in fake_logger.errors
    else:
        workflow.build_docker_image()

        if fail_at != 'exit':
            assert workflow.build_canceled
            assert ("plugin '%s_watched' raised an exception:" % fail_at +
                    " BuildCanceledException('Build was canceled',)",
                    ) in fake_logger.warnings
        else:
            assert not workflow.build_canceled

    assert watch_exit.was_called()
    assert watch_pre.was_called()

    if fail_at not in ['pre', 'buildstep']:
        assert watch_prepub.was_called()

    if fail_at not in ['pre', 'prepub', 'buildstep']:
        assert watch_post.was_called()