Exemplo n.º 1
0
    def test_create_installer(self):
        # create_installer() creates an iss-style installer and copies it
        # to the ci dir.
        with temp_dir() as iss_dir:
            with temp_dir() as ci_dir:
                installer_name = 'juju-setup-1.20.1.exe'

                def make_installer(*args, **kwargs):
                    output_dir = os.path.join(iss_dir, 'output')
                    os.makedirs(output_dir)
                    installer_path = os.path.join(
                        output_dir, installer_name)
                    with open(installer_path, 'w') as fake_installer:
                        fake_installer.write('juju installer')

                with patch('winbuildtest.run',
                           return_value='',
                           side_effect=make_installer) as run_mock:
                    devnull = open(os.devnull, 'w')
                    with patch('sys.stdout', devnull):
                        create_installer('1.20.1', iss_dir, ISS_CMD, ci_dir)
                        args, kwargs = run_mock.call_args
                        self.assertEqual((ISS_CMD, 'setup.iss'), args)
                        installer_path = os.path.join(ci_dir, installer_name)
                        self.assertTrue(os.path.isfile(installer_path))
Exemplo n.º 2
0
 def test_create_cloud_agent(self):
     # create_cloud_agent() creates an agent tgz from the jujud and
     # copies it to the ci dir.
     with temp_dir() as cmd_dir:
         with temp_dir() as ci_dir:
             with open('%s/jujud.exe' % cmd_dir, 'w') as fake_jujud:
                 fake_jujud.write('jujud')
             create_cloud_agent('1.20.1', cmd_dir, ci_dir)
             agent = os.path.join(ci_dir, 'juju-1.20.1-win2012-amd64.tgz')
             self.assertTrue(os.path.isfile(agent))
             with tarfile.open(name=agent, mode='r:gz') as tar:
                 self.assertEqual(['jujud.exe'], tar.getnames())
Exemplo n.º 3
0
 def test_upload_packages(self, up_mock):
     # assigning a side_effect requires an iterable, unlike instantiation.
     up_mock.side_effect = iter([False, True])
     team = Mock(name='bar', getPPAByName=Mock())
     team.getPPAByName.return_value = 'baz'
     lp = Mock(people={'bar': team})
     with temp_dir() as package_dir1:
         with temp_dir() as package_dir2:
             upload_packages(
                 lp, 'ppa:bar/baz', [package_dir1, package_dir2],
                 dry_run=False)
     call1 = call('ppa:bar/baz', 'baz', package_dir1, dry_run=False)
     call2 = call('ppa:bar/baz', 'baz', package_dir2, dry_run=False)
     self.assertEqual([call1, call2], up_mock.mock_calls)
     team.getPPAByName.assert_called_once_with(name='baz')
Exemplo n.º 4
0
 def test_consolidate_deps(self):
     expected_deps = {
         'github/foo': Dependency('github/foo', 'git', 'rev123', None),
         'github/bar': Dependency('github/bar', 'git', 'rev456', None),
         'github/baz': Dependency('github/baz', 'git', 'rev789', None),
         'github/qux': Dependency('github/qux', 'git', 'revdef', None),
         'lp/qoh': Dependency('lp/qoh', 'bzr', 'rev789', '3')
     }
     conflict_dep = Dependency('github/baz', 'git', 'revabc', None)
     with temp_dir() as base_dir:
         a_dep_file = '%s/a.tsv' % base_dir
         with open(a_dep_file, 'w') as f:
             f.write(expected_deps['github/foo'].to_line())
             f.write(expected_deps['github/bar'].to_line())
             f.write(expected_deps['github/baz'].to_line())
         b_dep_file = '%s/b.tsv' % base_dir
         with open(b_dep_file, 'w') as f:
             f.write(expected_deps['github/foo'].to_line())
             f.write(conflict_dep.to_line())
             f.write(expected_deps['github/qux'].to_line())
             f.write(expected_deps['lp/qoh'].to_line())
         dep_file = DependencyFile([a_dep_file, b_dep_file])
         deps, conflicts = dep_file.consolidate_deps()
     self.assertEqual([(b_dep_file, conflict_dep)], conflicts)
     self.assertEqual(expected_deps, deps)
 def test_sign_metadata(self):
     with patch('sign_metadata.run',
                autospec=True,
                side_effect=self.fake_gpg) as smr:
         with temp_dir() as meta_dir:
             meta_file = join(meta_dir, 'index.json')
             write_file(meta_file, self.content)
             with NamedTemporaryFile() as temp_file:
                 with patch('sign_metadata.NamedTemporaryFile',
                            autospec=True,
                            return_value=temp_file) as ntf:
                     sign_metadata('*****@*****.**', meta_dir)
                     self.verify_signed_content(meta_dir)
     signed_file = meta_file.replace('.json', '.sjson')
     gpg_file = '{}.gpg'.format(meta_file)
     calls = [
         call([
             'gpg', '--no-tty', '--clearsign', '--default-key',
             '*****@*****.**', '-o', signed_file, temp_file.name
         ]),
         call([
             'gpg', '--no-tty', '--detach-sign', '--default-key',
             '*****@*****.**', '-o', gpg_file, meta_file
         ])
     ]
     self.assertEqual(smr.mock_calls, calls)
     ntf.assert_called_once_with()
Exemplo n.º 6
0
 def test_consolidate_deps(self):
     expected_deps = {
         'github/foo': Dependency('github/foo', 'git', 'rev123', None),
         'github/bar': Dependency('github/bar', 'git', 'rev456', None),
         'github/baz': Dependency('github/baz', 'git', 'rev789', None),
         'github/qux': Dependency('github/qux', 'git', 'revdef', None),
         'lp/qoh': Dependency('lp/qoh', 'bzr', 'rev789', '3')
     }
     conflict_dep = Dependency('github/baz', 'git', 'revabc', None)
     with temp_dir() as base_dir:
         a_dep_file = '%s/a.tsv' % base_dir
         with open(a_dep_file, 'w') as f:
             f.write(expected_deps['github/foo'].to_line())
             f.write(expected_deps['github/bar'].to_line())
             f.write(expected_deps['github/baz'].to_line())
         b_dep_file = '%s/b.tsv' % base_dir
         with open(b_dep_file, 'w') as f:
             f.write(expected_deps['github/foo'].to_line())
             f.write(conflict_dep.to_line())
             f.write(expected_deps['github/qux'].to_line())
             f.write(expected_deps['lp/qoh'].to_line())
         dep_file = DependencyFile([a_dep_file, b_dep_file])
         deps, conflicts = dep_file.consolidate_deps()
     self.assertEqual([(b_dep_file, conflict_dep)], conflicts)
     self.assertEqual(expected_deps, deps)
 def test_cpc_generate_mirrors_file_deprecated_tree(self):
     updated = datetime.datetime.utcnow()
     with temp_dir() as base_path:
         stream_path = '%s/devel/tools/streams/v1' % base_path
         os.makedirs(stream_path)
         generate_cpc_mirrors_file(updated, stream_path)
         mirror_path = '%s/cpc-mirrors.json' % stream_path
         self.assertTrue(os.path.isfile(mirror_path))
         with open(mirror_path) as mirror_file:
             data = json.load(mirror_file)
     product_name = 'com.ubuntu.juju:released:tools'
     self.assertEqual([product_name], data['mirrors'].keys())
     purposeful_mirror = data['mirrors'][product_name]
     purpose = product_name.split(':')[1]
     self.assertEqual('streams/v1/com.ubuntu.juju-%s-tools.json' % purpose,
                      purposeful_mirror[0]['path'])
     self.assertEqual('https://juju-dist.s3.amazonaws.com/devel/tools',
                      purposeful_mirror[0]['mirror'])
     self.assertEqual(11, len(purposeful_mirror[0]['clouds']))
     self.assertEqual(
         'https://jujutools.blob.core.windows.net'
         '/juju-tools/devel/tools', purposeful_mirror[1]['mirror'])
     self.assertEqual(17, len(purposeful_mirror[1]['clouds']))
     self.assertEqual(("https://us-east.manta.joyent.com/"
                       "cpcjoyentsupport/public/juju-dist/devel/tools"),
                      purposeful_mirror[2]['mirror'])
     self.assertEqual(6, len(purposeful_mirror[2]['clouds']))
    def test_get_filenames_url(self):
        with temp_dir() as temp:
            with temp_cwd(temp):
                h_file, j_file = cloud_weather_report.get_filenames(
                    'http://example.com/~git')
        self.assertTrue(h_file.startswith(
            'results/http___example_com__git') and h_file.endswith('.html'))
        self.assertTrue(j_file.startswith(
            'results/http___example_com__git') and j_file.endswith('.json'))

        with temp_dir() as temp:
            with temp_cwd(temp):
                h_file, j_file = cloud_weather_report.get_filenames(
                    'cs:~user/mysql-benchmark')
        self.assertTrue(j_file.startswith(
            'results/cs__user_mysql_benchmark') and j_file.endswith('.json'))
Exemplo n.º 9
0
 def test_make_client_tarball(self):
     with temp_dir() as base_dir:
         cmd_dir = os.path.join(base_dir, 'foo')
         os.makedirs(cmd_dir)
         juju_binary = os.path.join(cmd_dir, 'juju')
         readme_file = os.path.join(cmd_dir, 'README.txt')
         for path in [juju_binary, readme_file]:
             with open(path, 'w') as jb:
                 jb.write('juju')
         os.chmod(juju_binary, 0o775)
         os.chmod(readme_file, 0o664)
         make_client_tarball(
             'osx', [juju_binary, readme_file], '1.2.3', base_dir)
         osx_tarball_path = os.path.join(base_dir, 'juju-1.2.3-osx.tar.gz')
         self.assertTrue(os.path.isfile(osx_tarball_path))
         with tarfile.open(osx_tarball_path, 'r:gz') as tar:
             self.assertEqual(
                 ['juju-bin', 'juju-bin/juju', 'juju-bin/README.txt'],
                 tar.getnames())
             self.assertEqual(
                 0o775, tar.getmember('juju-bin').mode)
             self.assertEqual(
                 0o775, tar.getmember('juju-bin/juju').mode)
             self.assertEqual(
                 0o664, tar.getmember('juju-bin/README.txt').mode)
Exemplo n.º 10
0
 def test_cpc_generate_mirrors_file_deprecated_tree(self):
     updated = datetime.datetime.utcnow()
     with temp_dir() as base_path:
         stream_path = '%s/devel/tools/streams/v1' % base_path
         os.makedirs(stream_path)
         generate_cpc_mirrors_file(updated, stream_path)
         mirror_path = '%s/cpc-mirrors.json' % stream_path
         self.assertTrue(os.path.isfile(mirror_path))
         with open(mirror_path) as mirror_file:
             data = json.load(mirror_file)
     product_name = 'com.ubuntu.juju:released:tools'
     self.assertEqual([product_name], data['mirrors'].keys())
     purposeful_mirror = data['mirrors'][product_name]
     purpose = product_name.split(':')[1]
     self.assertEqual(
         'streams/v1/com.ubuntu.juju-%s-tools.json' % purpose,
         purposeful_mirror[0]['path'])
     self.assertEqual(
         'https://juju-dist.s3.amazonaws.com/devel/tools',
         purposeful_mirror[0]['mirror'])
     self.assertEqual(11, len(purposeful_mirror[0]['clouds']))
     self.assertEqual(
         'https://jujutools.blob.core.windows.net'
         '/juju-tools/devel/tools',
         purposeful_mirror[1]['mirror'])
     self.assertEqual(17, len(purposeful_mirror[1]['clouds']))
     self.assertEqual(
         ("https://us-east.manta.joyent.com/"
          "cpcjoyentsupport/public/juju-dist/devel/tools"),
         purposeful_mirror[2]['mirror'])
     self.assertEqual(6, len(purposeful_mirror[2]['clouds']))
 def test_cpc_generate_mirrors_file(self):
     updated = datetime.datetime.utcnow()
     with temp_dir() as base_path:
         stream_path = '%s/tools/streams/v1' % base_path
         os.makedirs(stream_path)
         generate_cpc_mirrors_file(updated, stream_path)
         mirror_path = '%s/cpc-mirrors.json' % stream_path
         self.assertTrue(os.path.isfile(mirror_path))
         with open(mirror_path) as mirror_file:
             data = json.load(mirror_file)
     self.assertEqual(['format', 'mirrors', 'updated'], sorted(data.keys()))
     self.assertEqual('mirrors:1.0', data['format'])
     expected_updated = updated.strftime('%a, %d %b %Y %H:%M:%S -0000')
     self.assertEqual(expected_updated, data['updated'])
     expected_produts = sorted('com.ubuntu.juju:%s:tools' % p
                               for p in PURPOSES)
     for product_name in expected_produts:
         purposeful_mirrors = data['mirrors'][product_name]
         purpose = product_name.split(':')[1]
         self.assertEqual(
             'streams/v1/com.ubuntu.juju-%s-tools.json' % purpose,
             purposeful_mirrors[0]['path'])
         self.assertEqual('https://juju-dist.s3.amazonaws.com/tools',
                          purposeful_mirrors[0]['mirror'])
         self.assertEqual(11, len(purposeful_mirrors[0]['clouds']))
         self.assertEqual(
             'https://jujutools.blob.core.windows.net/juju-tools/tools',
             purposeful_mirrors[1]['mirror'])
         self.assertEqual(17, len(purposeful_mirrors[1]['clouds']))
         self.assertEqual(("https://us-east.manta.joyent.com/"
                           "cpcjoyentsupport/public/juju-dist/tools"),
                          purposeful_mirrors[2]['mirror'])
         self.assertEqual(6, len(purposeful_mirrors[2]['clouds']))
Exemplo n.º 12
0
 def test_cpc_generate_mirrors_file(self):
     updated = datetime.datetime.utcnow()
     with temp_dir() as base_path:
         stream_path = '%s/tools/streams/v1' % base_path
         os.makedirs(stream_path)
         generate_cpc_mirrors_file(updated, stream_path)
         mirror_path = '%s/cpc-mirrors.json' % stream_path
         self.assertTrue(os.path.isfile(mirror_path))
         with open(mirror_path) as mirror_file:
             data = json.load(mirror_file)
     self.assertEqual(['format', 'mirrors', 'updated'], sorted(data.keys()))
     self.assertEqual('mirrors:1.0', data['format'])
     expected_updated = updated.strftime('%a, %d %b %Y %H:%M:%S -0000')
     self.assertEqual(expected_updated, data['updated'])
     expected_produts = sorted(
         'com.ubuntu.juju:%s:tools' % p for p in PURPOSES)
     for product_name in expected_produts:
         purposeful_mirrors = data['mirrors'][product_name]
         purpose = product_name.split(':')[1]
         self.assertEqual(
             'streams/v1/com.ubuntu.juju-%s-tools.json' % purpose,
             purposeful_mirrors[0]['path'])
         self.assertEqual(
             'https://juju-dist.s3.amazonaws.com/tools',
             purposeful_mirrors[0]['mirror'])
         self.assertEqual(11, len(purposeful_mirrors[0]['clouds']))
         self.assertEqual(
             'https://jujutools.blob.core.windows.net/juju-tools/tools',
             purposeful_mirrors[1]['mirror'])
         self.assertEqual(17, len(purposeful_mirrors[1]['clouds']))
         self.assertEqual(
             ("https://us-east.manta.joyent.com/"
              "cpcjoyentsupport/public/juju-dist/tools"),
             purposeful_mirrors[2]['mirror'])
         self.assertEqual(6, len(purposeful_mirrors[2]['clouds']))
Exemplo n.º 13
0
 def test_upload_changes(self):
     # Only new and changed files are uploaded.
     md5 = hashlib.md5()
     md5.update('one')
     one_hash = md5.hexdigest()
     with temp_dir() as base:
         remote_name = os.path.join(base, 'one')
         remote_files = {
             remote_name: {
                 'name': remote_name,
                 'hash': one_hash
             }
         }
         local_files = make_local_files(base, ['one', 'two'])
         args = Namespace(container='foo',
                          path=base,
                          files=local_files,
                          verbose=False,
                          dry_run=False)
         with patch('subprocess.check_output',
                    autospec=True,
                    return_value='two') as co_mock:
             uploaded_files = upload_changes(args, remote_files)
     self.assertEqual(['two'], uploaded_files)
     co_mock.assert_called_once_with(
         ['swift', 'upload', base,
          os.path.join(base, 'two')])
Exemplo n.º 14
0
 def test_parse_args_signing_passphrase_file(self):
     with temp_dir() as metadata_dir:
         with NamedTemporaryFile() as pass_file:
             args = parse_args([metadata_dir, 's_key',
                                '--signing-passphrase-file', pass_file.name])
     self.assertEqual(args, Namespace(
         signing_key='s_key', signing_passphrase_file=pass_file.name,
         metadata_dir=metadata_dir))
Exemplo n.º 15
0
 def test_no_patchdir(self):
     stream = StringIO.StringIO()
     with temp_dir() as basedir:
         with self.assertRaises(SystemExit):
             with mock.patch("sys.stderr", stream):
                 main(["test", os.path.join(basedir, "missing"), basedir])
     self.assertRegexpMatches(
         stream.getvalue(), "Could not list patch directory: .*/missing")
Exemplo n.º 16
0
 def test_no_patchdir(self):
     stream = StringIO.StringIO()
     with temp_dir() as basedir:
         with self.assertRaises(SystemExit):
             with mock.patch("sys.stderr", stream):
                 main(["test", os.path.join(basedir, "missing"), basedir])
     self.assertRegexpMatches(stream.getvalue(),
                              "Could not list patch directory: .*/missing")
Exemplo n.º 17
0
 def test_parse_args_default(self):
     with temp_dir() as metadata_dir:
         args = parse_args([metadata_dir, 's_key'])
     self.assertEqual(
         args,
         Namespace(signing_key='s_key',
                   signing_passphrase_file=None,
                   metadata_dir=metadata_dir))
Exemplo n.º 18
0
 def test_working_directory(self):
     this_dir = os.getcwd()
     with temp_dir() as base_dir:
         new_dir = os.path.join(base_dir, 'juju-core_1.2.3')
         os.makedirs(new_dir)
         with working_directory(new_dir):
             self.assertEqual(os.path.realpath(new_dir), os.getcwd())
     self.assertEqual(this_dir, os.getcwd())
Exemplo n.º 19
0
 def test_no_srctree(self):
     stream = StringIO.StringIO()
     with temp_dir() as basedir:
         with self.assertRaises(SystemExit):
             with mock.patch("sys.stderr", stream):
                 main(["test", basedir, os.path.join(basedir, "missing")])
     self.assertRegexpMatches(stream.getvalue(),
                              "Source tree '.*/missing' not a directory")
Exemplo n.º 20
0
 def test_no_srctree(self):
     stream = StringIO.StringIO()
     with temp_dir() as basedir:
         with self.assertRaises(SystemExit):
             with mock.patch("sys.stderr", stream):
                 main(["test", basedir, os.path.join(basedir, "missing")])
     self.assertRegexpMatches(
         stream.getvalue(), "Source tree '.*/missing' not a directory")
Exemplo n.º 21
0
 def test_working_directory(self):
     this_dir = os.getcwd()
     with temp_dir() as base_dir:
         new_dir = os.path.join(base_dir, 'juju-core_1.2.3')
         os.makedirs(new_dir)
         with working_directory(new_dir):
             self.assertEqual(os.path.realpath(new_dir), os.getcwd())
     self.assertEqual(this_dir, os.getcwd())
Exemplo n.º 22
0
 def test_write_item_streams(self):
     now = datetime(2001, 2, 3)
     east_image = make_mock_image(region_name='us-east-1')
     west_image = make_mock_image(region_name='us-west-1')
     items = [make_item(west_image, now), make_item(east_image, now)]
     with temp_dir() as streams:
         with patch('simplestreams.util.timestamp',
                    return_value='now'):
             with patch('sys.stderr'):
                 write_item_streams(items, streams)
         self.assertFalse(
             os.path.exists(os.path.join(streams, 'streams', 'v1',
                                         'index2.json')))
         index = load_json(streams, 'index.json')
         releases = load_json(streams, 'com.ubuntu.cloud.released-aws.json')
     self.assertEqual(
         {'format': 'index:1.0', 'updated': 'now', 'index': {
             'com.ubuntu.cloud.released:aws': {
                 'format': 'products:1.0',
                 'updated': 'now',
                 'datatype': 'image-ids',
                 'path': 'streams/v1/com.ubuntu.cloud.released-aws.json',
                 'products': ['com.ubuntu.cloud:server:centos7:amd64'],
                 }
             }}, index)
     expected = {
         'content_id': 'com.ubuntu.cloud.released:aws',
         'format': 'products:1.0',
         'updated': 'now',
         'datatype': 'image-ids',
         'products': {'com.ubuntu.cloud:server:centos7:amd64': {
             'endpoint': 'https://foo',
             'arch': 'amd64',
             'release_title': 'Centos 7',
             'label': 'release',
             'release_codename': 'centos7',
             'version': 'centos7',
             'release': 'centos7',
             'os': 'centos',
             'versions': {'20010203': {
                 'items': {
                     'usww1he': {
                         'id': 'qux',
                         'region': 'us-west-1',
                         'root_store': 'ebs',
                         'virt': 'hvm',
                         },
                     'usee1he': {
                         'id': 'qux',
                         'region': 'us-east-1',
                         'root_store': 'ebs',
                         'virt': 'hvm',
                         },
                     }
                 }},
             }},
         }
     self.assertEqual(releases, expected)
Exemplo n.º 23
0
 def test_generate_index_file(self):
     updated = datetime.datetime.utcnow()
     with temp_dir() as base_path:
         stream_path = '%s/tools/streams/v1' % base_path
         os.makedirs(stream_path)
         generate_index_file(updated, stream_path)
         index_path = '%s/index.json' % stream_path
         self.assertTrue(os.path.isfile(index_path))
         with open(index_path) as index_file:
             data = json.load(index_file)
     self.assertEqual(['format', 'index', 'updated'], sorted(data.keys()))
     self.assertEqual('index:1.0', data['format'])
     expected_updated = updated.strftime('%a, %d %b %Y %H:%M:%S -0000')
     self.assertEqual(expected_updated, data['updated'])
     product_name = 'com.ubuntu.juju:released:tools'
     self.assertEqual([product_name], data['index'].keys())
     released_index = data['index'][product_name]
     self.assertEqual(
         ['datatype', 'format', 'path', 'products', 'updated'],
         sorted(released_index.keys()))
     self.assertEqual('content-download', released_index['datatype'])
     self.assertEqual('products:1.0', released_index['format'])
     self.assertEqual(
         'streams/v1/com.ubuntu.juju:released:tools.json',
         released_index['path'])
     self.assertEqual(expected_updated, released_index['updated'])
     self.assertEqual(
         ['com.ubuntu.juju:12.04:amd64',
          'com.ubuntu.juju:12.04:armhf',
          'com.ubuntu.juju:12.04:i386',
          'com.ubuntu.juju:12.10:amd64',
          'com.ubuntu.juju:12.10:i386',
          'com.ubuntu.juju:13.04:amd64',
          'com.ubuntu.juju:13.04:i386',
          'com.ubuntu.juju:13.10:amd64',
          'com.ubuntu.juju:13.10:armhf',
          'com.ubuntu.juju:13.10:i386',
          'com.ubuntu.juju:14.04:amd64',
          'com.ubuntu.juju:14.04:arm64',
          'com.ubuntu.juju:14.04:armhf',
          'com.ubuntu.juju:14.04:i386',
          'com.ubuntu.juju:14.04:powerpc',
          'com.ubuntu.juju:14.04:ppc64',
          'com.ubuntu.juju:14.04:ppc64el',
          'com.ubuntu.juju:14.10:amd64',
          'com.ubuntu.juju:14.10:arm64',
          'com.ubuntu.juju:14.10:armhf',
          'com.ubuntu.juju:14.10:i386',
          'com.ubuntu.juju:14.10:ppc64',
          'com.ubuntu.juju:14.10:ppc64el',
          'com.ubuntu.juju:15.04:amd64',
          'com.ubuntu.juju:15.04:arm64',
          'com.ubuntu.juju:15.04:armhf',
          'com.ubuntu.juju:15.04:i386',
          'com.ubuntu.juju:15.04:ppc64',
          'com.ubuntu.juju:15.04:ppc64el'],
         released_index['products'])
Exemplo n.º 24
0
 def test_setup_local(self):
     with temp_dir() as workspace:
         source_files = make_source_files(workspace, 'my.dsc')
         build_dir = setup_local(
             workspace, 'trusty', 'i386', source_files, verbose=False)
         self.assertEqual(
             os.path.join(workspace, 'juju-build-trusty-i386'),
             build_dir)
         self.assertTrue(os.path.isdir(build_dir))
Exemplo n.º 25
0
 def test_diff_files(self, gr_mock):
     gr_mock.return_value = 'one\ntwo\nthree'
     with temp_dir() as base:
         local_path = os.path.join(base, 'bar.json')
         with open(local_path, 'w') as local_file:
             local_file.write('one\ntwo\nthree')
         identical, diff = diff_files(local_path, 'http://foo/bar.json')
     self.assertTrue(identical)
     self.assertIsNone(diff)
     gr_mock.assert_called_with('http://foo/bar.json')
Exemplo n.º 26
0
 def test_includes_mirror(self):
     with temp_dir() as local_dir:
         foo_path = os.path.join(local_dir, 'foo-mirror')
         expected = [
             SyncFile('bools/foo-mirror', size=3, local_path=foo_path,
                      md5content=md5sum['bar'], mimetype=None),
             ]
         write_file(foo_path, 'bar')
         result = get_local_sync_files('bools', local_dir)
         self.assertEqual(expected, result)
    def test_get_filenames_url(self):
        with temp_dir() as temp:
            with temp_cwd(temp):
                h_file, j_file = cloud_weather_report.get_filenames(
                    'http://example.com/~git')
        self.assertTrue(
            h_file.startswith('results/http___example_com__git')
            and h_file.endswith('.html'))
        self.assertTrue(
            j_file.startswith('results/http___example_com__git')
            and j_file.endswith('.json'))

        with temp_dir() as temp:
            with temp_cwd(temp):
                h_file, j_file = cloud_weather_report.get_filenames(
                    'cs:~user/mysql-benchmark')
        self.assertTrue(
            j_file.startswith('results/cs__user_mysql_benchmark')
            and j_file.endswith('.json'))
 def test_diff_files(self, gr_mock):
     gr_mock.return_value = 'one\ntwo\nthree'
     with temp_dir() as base:
         local_path = os.path.join(base, 'bar.json')
         with open(local_path, 'w') as local_file:
             local_file.write('one\ntwo\nthree')
         identical, diff = diff_files(local_path, 'http://foo/bar.json')
     self.assertTrue(identical)
     self.assertIsNone(diff)
     gr_mock.assert_called_with('http://foo/bar.json')
Exemplo n.º 29
0
 def test_go_tarball_gopath(self):
     with temp_dir() as base_dir:
         src_path = os.path.join(base_dir, 'juju-core_1.2.3')
         os.makedirs(src_path)
         tarball_path = '%s.tar.gz' % src_path
         with tarfile.open(tarball_path, 'w:gz') as tar:
             tar.add(src_path, arcname='juju-core_1.2.3')
         with go_tarball(tarball_path) as (gopath, version):
             self.assertTrue(os.path.isdir(gopath))
             self.assertTrue(gopath.endswith('juju-core_1.2.3'), gopath)
             self.assertEqual('1.2.3', version)
Exemplo n.º 30
0
 def test_find_agents(self):
     products = make_products_data(['1.20.7', '1.20.8'])
     with temp_dir() as wd:
         file_path = '{}/json'.format(wd)
         with open(file_path, 'w') as f:
             f.write(json.dumps(products))
         agents = find_agents(file_path)
     expected = [
         '1.20.7-trusty-i386', '1.20.7-trusty-amd64',
         '1.20.8-trusty-amd64', '1.20.8-trusty-i386']
     self.assertEqual(expected, agents.keys())
Exemplo n.º 31
0
 def test_get_changes(self):
     with temp_dir() as package_dir:
         changes_path = os.path.join(package_dir, 'foo_source.changes')
         with open(changes_path, 'w') as changes_file:
             changes_file.write(CHANGES_DATA)
         with open(os.path.join(package_dir, 'foo.dsc'), 'w') as other_file:
             other_file.write('other_file')
         source_name, version, file_name = get_changes(package_dir)
     self.assertEqual('juju-core', source_name)
     self.assertEqual('1.24.5-0ubuntu1~14.04.1~juju1', version)
     self.assertEqual('foo_source.changes', file_name)
Exemplo n.º 32
0
 def test_delete_tmp_tsv(self):
     dep_file = DependencyFile([])
     self.assertFalse(dep_file.delete_tmp_tsv())
     with temp_dir() as base_dir:
         dep_path = '%s/a.tsv' % base_dir
         with open(dep_path, 'w') as f:
             f.write('foo')
         dep_file.tmp_tsv = dep_path
         self.assertTrue(dep_file.delete_tmp_tsv())
         self.assertFalse(os.path.isfile(dep_path))
     self.assertIsNone(dep_file.tmp_tsv)
Exemplo n.º 33
0
 def test_build_agent(self):
     # build_agent creates a win amd64 jujud.
     with temp_dir() as jujud_cmd_dir:
         with patch('winbuildtest.run', return_value='') as run_mock:
             devnull = open(os.devnull, 'w')
             with patch('sys.stdout', devnull):
                 build_agent(jujud_cmd_dir, GO_CMD, GOPATH)
                 args, kwargs = run_mock.call_args
                 self.assertEqual((GO_CMD, 'build'), args)
                 self.assertEqual('amd64', kwargs['env'].get('GOARCH'))
                 self.assertEqual(GOPATH, kwargs['env'].get('GOPATH'))
Exemplo n.º 34
0
 def test_build_in_lxc_stop_lxc(self, oc_mock, cc_mock):
     with temp_dir() as workspace:
         source_files = make_source_files(workspace, 'my.dsc')
         build_dir = setup_local(
             workspace, 'trusty', 'i386', source_files, verbose=False)
         with patch('subprocess.Popen', side_effect=Exception):
             with self.assertRaises(Exception):
                 build_in_lxc('trusty-i386', build_dir, verbose=False)
     cc_mock.assert_any_call(['sudo', 'lxc-stop', '-n', 'trusty-i386'])
     cc_mock.assert_any_call(['sudo', 'chown', '-R', 'bingo', build_dir])
     oc_mock.assert_any_call(build_dir, 0o775)
Exemplo n.º 35
0
 def test_move_debs(self):
     with temp_dir() as workspace:
         build_dir = os.path.join(workspace, 'juju-build-trusty-i386')
         os.makedirs(build_dir)
         deb_file = os.path.join(build_dir, 'my.deb')
         with open(deb_file, 'w') as f:
             f.write('deb')
         found = move_debs(build_dir, workspace)
         self.assertTrue(found)
         self.assertFalse(os.path.isfile(deb_file))
         self.assertTrue(os.path.isfile(os.path.join(workspace, 'my.deb')))
Exemplo n.º 36
0
 def test_get_meta_files(self):
     with temp_dir() as meta_dir:
         file1 = join(meta_dir, "index.json")
         file2 = join(meta_dir, "proposed-tools.json")
         file3 = join(meta_dir, "random.txt")
         open(file1, 'w').close()
         open(file2, 'w').close()
         open(file3, 'w').close()
         meta_files = get_meta_files(meta_dir)
         self.assertItemsEqual(meta_files,
                               ['index.json', 'proposed-tools.json'])
Exemplo n.º 37
0
 def test_move_debs(self):
     with temp_dir() as workspace:
         build_dir = os.path.join(workspace, 'juju-build-trusty-i386')
         os.makedirs(build_dir)
         deb_file = os.path.join(build_dir, 'my.deb')
         with open(deb_file, 'w') as f:
             f.write('deb')
         found = move_debs(build_dir, workspace)
         self.assertTrue(found)
         self.assertFalse(os.path.isfile(deb_file))
         self.assertTrue(os.path.isfile(os.path.join(workspace, 'my.deb')))
Exemplo n.º 38
0
 def test_setup_local(self):
     with temp_dir() as workspace:
         source_files = make_source_files(workspace, 'my.dsc')
         build_dir = setup_local(workspace,
                                 'trusty',
                                 'i386',
                                 source_files,
                                 verbose=False)
         self.assertEqual(os.path.join(workspace, 'juju-build-trusty-i386'),
                          build_dir)
         self.assertTrue(os.path.isdir(build_dir))
Exemplo n.º 39
0
def main():

    # Parse arguments
    parser = argparse.ArgumentParser(description='Spawn px4 controller for SITL')
    parser.add_argument('-model', type=str, default="mbzirc",
                        help='robot model name, must match xacro description folder name')
    parser.add_argument('-id', type=int, default=1,
                        help='robot id, used to compute udp ports')
    parser.add_argument('-description_package', type=str, default="robots_description",
                        help='robot description package, must follow robots_description file structure')
    args, unknown = parser.parse_known_args()
    utils.check_unknown_args(unknown)

    # Get an instance of RosPack with the default search paths
    rospack = rospkg.RosPack()

    # Create temporary directory for robot sitl stuff
    temp_dir = utils.temp_dir(args.id)
    subprocess.call("mkdir -p " + temp_dir, shell=True)
    subprocess.call("rm -rf " + temp_dir + "/rootfs", shell=True)

    # Get udp configuration, depending on id
    udp_config = utils.udp_config(args.id)

    # Modify commands file to fit robot ports
    commands_file = rospack.get_path(args.description_package) + "/models/" + args.model + "/px4cmd"
    modified_cmds = temp_dir + "/cmds"
    with open(commands_file, 'r') as origin, open(modified_cmds, 'w') as modified:
        for line in origin:
            modified_line = line\
            .replace("_SIMPORT_", str(udp_config["sim_port"]))\
            .replace("_MAVPORT_", str(udp_config["u_port"][0]))\
            .replace("_MAVPORT2_", str(udp_config["u_port"][1]))\
            .replace("_MAVOPORT_", str(udp_config["o_port"][0]))\
            .replace("_MAVOPORT2_", str(udp_config["o_port"][1]))\
            .replace("_MAVSYSID_", str(args.id))
            modified.write(modified_line)

    # Spawn px4
    px4_src = rospack.get_path("px4")
    px4_bin = px4_src + "/build/posix_sitl_default/px4"
    px4_args = px4_bin + " " + px4_src + " " + modified_cmds
    px4_out = open(temp_dir+"/px4.out", 'w')
    px4_err = open(temp_dir+"/px4.err", 'w')
    px4 = subprocess.Popen(px4_args, shell=True, stdout=px4_out, stderr=px4_err, cwd=temp_dir)

    # Wait for it!
    try:
        px4.wait()
    except KeyboardInterrupt:
        pass
    finally:
        px4_out.close()
        px4_err.close()
Exemplo n.º 40
0
 def test_get_meta_files(self):
     with temp_dir() as meta_dir:
         file1 = join(meta_dir, "index.json")
         file2 = join(meta_dir, "proposed-tools.json")
         file3 = join(meta_dir, "random.txt")
         open(file1, 'w').close()
         open(file2, 'w').close()
         open(file3, 'w').close()
         meta_files = get_meta_files(meta_dir)
         self.assertItemsEqual(
             meta_files, ['index.json', 'proposed-tools.json'])
Exemplo n.º 41
0
 def test_delete_tmp_tsv(self):
     dep_file = DependencyFile([])
     self.assertFalse(dep_file.delete_tmp_tsv())
     with temp_dir() as base_dir:
         dep_path = '%s/a.tsv' % base_dir
         with open(dep_path, 'w') as f:
             f.write('foo')
         dep_file.tmp_tsv = dep_path
         self.assertTrue(dep_file.delete_tmp_tsv())
         self.assertFalse(os.path.isfile(dep_path))
     self.assertIsNone(dep_file.tmp_tsv)
Exemplo n.º 42
0
 def test_go_tarball_gopath(self):
     with temp_dir() as base_dir:
         src_path = os.path.join(base_dir, 'juju-core_1.2.3')
         os.makedirs(src_path)
         tarball_path = '%s.tar.gz' % src_path
         with tarfile.open(tarball_path, 'w:gz') as tar:
             tar.add(src_path, arcname='juju-core_1.2.3')
         with go_tarball(tarball_path) as (gopath, version):
             self.assertTrue(os.path.isdir(gopath))
             self.assertTrue(gopath.endswith('juju-core_1.2.3'), gopath)
             self.assertEqual('1.2.3', version)
Exemplo n.º 43
0
 def test_is_new_version(self):
     agent = 's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz'
     with temp_dir() as base:
         local_agent = os.path.join(base, 'juju-1.21.0-win2012-amd64.tgz')
         with open(local_agent, 'w') as f:
             f.write('agent')
         with patch('agent_archive.run', return_value='') as mock:
             result = is_new_version(
                 local_agent, 'config', S3_CONTAINER_FAKE, verbose=False)
         self.assertTrue(result)
         mock.assert_called_with(
             ['ls', '--list-md5', agent], config='config', verbose=False)
 def test_one_remote_file(self):
     args = Namespace(verbose=False, dry_run=False)
     expected = SyncFile('index.json', 33, 'md5-asdf', 'application/json',
                         '')
     service = FakeBlobService(
         {'tools/index.json': FakeBlob.from_sync_file(expected)})
     with temp_dir() as local_dir:
         sync_files(service, 'tools', local_dir, args)
     self.assertEqual(['tools/index.json'],
                      service.containers[JUJU_DIST].keys())
     blob = service.containers[JUJU_DIST]['tools/index.json']
     self.assertEqual({}, blob._blocks)
Exemplo n.º 45
0
    def test_build_client(self):
        # build_client() builds the juju client with go and moved the
        # exe to the iss dir.
        with temp_dir() as cmd_dir:
            with temp_dir() as iss_dir:

                def make_juju(*args, **kwargs):
                    with open('%s/juju.exe' % cmd_dir, 'w') as fake_juju:
                        fake_juju.write('juju')

                with patch('winbuildtest.run',
                           return_value='', side_effect=make_juju) as run_mock:
                    devnull = open(os.devnull, 'w')
                    with patch('sys.stdout', devnull):
                        build_client(cmd_dir, GO_CMD, GOPATH, iss_dir)
                        args, kwargs = run_mock.call_args
                        self.assertEqual((GO_CMD, 'build'), args)
                        self.assertEqual('386', kwargs['env'].get('GOARCH'))
                        self.assertEqual(GOPATH, kwargs['env'].get('GOPATH'))
                        client_path = os.path.join(iss_dir, 'juju.exe')
                        self.assertTrue(os.path.isfile(client_path))
Exemplo n.º 46
0
 def test_is_new_version_idential(self):
     listing = (
         '2015-05-27 14:16   8292541   b33aed8f3134996703dc39f9a7c95783  '
         's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz')
     with temp_dir() as base:
         local_agent = os.path.join(base, 'juju-1.21.0-win2012-amd64.tgz')
         with open(local_agent, 'w') as f:
             f.write('agent')
         with patch('agent_archive.run', return_value=listing):
             result = is_new_version(local_agent, 'config',
                                     S3_CONTAINER_FAKE)
     self.assertFalse(result)
Exemplo n.º 47
0
 def test_non_patch(self):
     with temp_dir() as basedir:
         patchdir = os.path.join(basedir, "patches")
         os.mkdir(patchdir)
         patch_a = os.path.join(patchdir, "readme.txt")
         open(patch_a, "w").close()
         with self.patch_output() as messages:
             with mock.patch(
                     "apply_patches.apply_patch", autospec=True) as ap_mock:
                 main(["test", "--verbose", patchdir, basedir])
         self.assertEqual(ap_mock.mock_calls, [])
         self.assertEqual(messages, [u"Applying 0 patches"])
 def test_find_agents(self):
     products = make_products_data(['1.20.7', '1.20.8'])
     with temp_dir() as wd:
         file_path = '{}/json'.format(wd)
         with open(file_path, 'w') as f:
             f.write(json.dumps(products))
         agents = find_agents(file_path)
     expected = [
         '1.20.7-trusty-i386', '1.20.7-trusty-amd64', '1.20.8-trusty-amd64',
         '1.20.8-trusty-i386'
     ]
     self.assertEqual(expected, agents.keys())
Exemplo n.º 49
0
 def test_parse_args_signing_passphrase_file(self):
     with temp_dir() as metadata_dir:
         with NamedTemporaryFile() as pass_file:
             args = parse_args([
                 metadata_dir, 's_key', '--signing-passphrase-file',
                 pass_file.name
             ])
     self.assertEqual(
         args,
         Namespace(signing_key='s_key',
                   signing_passphrase_file=pass_file.name,
                   metadata_dir=metadata_dir))
Exemplo n.º 50
0
 def test_non_patch(self):
     with temp_dir() as basedir:
         patchdir = os.path.join(basedir, "patches")
         os.mkdir(patchdir)
         patch_a = os.path.join(patchdir, "readme.txt")
         open(patch_a, "w").close()
         with self.patch_output() as messages:
             with mock.patch("apply_patches.apply_patch",
                             autospec=True) as ap_mock:
                 main(["test", "--verbose", patchdir, basedir])
         self.assertEqual(ap_mock.mock_calls, [])
         self.assertEqual(messages, [u"Applying 0 patches"])
Exemplo n.º 51
0
 def test_is_new_version_idential(self):
     listing = (
         '2015-05-27 14:16   8292541   b33aed8f3134996703dc39f9a7c95783  '
         's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz')
     with temp_dir() as base:
         local_agent = os.path.join(base, 'juju-1.21.0-win2012-amd64.tgz')
         with open(local_agent, 'w') as f:
             f.write('agent')
         with patch('agent_archive.run', return_value=listing):
             result = is_new_version(local_agent, 'config',
                                     S3_CONTAINER_FAKE)
     self.assertFalse(result)
 def test_get_filenames(self):
     with temp_dir() as temp:
         with temp_cwd(temp):
             h_file, j_file = cloud_weather_report.get_filenames('git')
         static_path = os.path.join(temp, 'results', 'static')
         self.assertTrue(os.path.isdir(static_path))
         self.assertTrue(os.path.isdir(os.path.join(static_path, 'css')))
         self.assertTrue(os.path.isdir(os.path.join(static_path, 'images')))
         self.assertTrue(os.path.isdir(os.path.join(static_path, 'js')))
     self.assertTrue(h_file.startswith('results/git-') and
                     h_file.endswith('.html'))
     self.assertTrue(j_file.startswith('results/git-') and
                     j_file.endswith('.json'))
 def test_get_filenames(self):
     with temp_dir() as temp:
         with temp_cwd(temp):
             h_file, j_file = cloud_weather_report.get_filenames('git')
         static_path = os.path.join(temp, 'results', 'static')
         self.assertTrue(os.path.isdir(static_path))
         self.assertTrue(os.path.isdir(os.path.join(static_path, 'css')))
         self.assertTrue(os.path.isdir(os.path.join(static_path, 'images')))
         self.assertTrue(os.path.isdir(os.path.join(static_path, 'js')))
     self.assertTrue(
         h_file.startswith('results/git-') and h_file.endswith('.html'))
     self.assertTrue(
         j_file.startswith('results/git-') and j_file.endswith('.json'))