Exemplo n.º 1
0
func (r *Release) validateSpecificDevReleasePathStructure() error {
	if err := util.ValidatePath(r.getDevReleaseManifestsDir(), true, "release dev manifests directory"); err != nil {
		return err
	}

	if err := util.ValidatePath(r.getDevReleaseIndexPath(), false, "release index file"); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 2
0
func TestDevReleaseJobExtractOk(t *testing.T) {
	assert := assert.New(t)

	workDir, err := os.Getwd()
	assert.NoError(err)

	emptyDevReleasePath := filepath.Join(workDir, "../test-assets/test-dev-release")
	emptyDevReleaseCachePath := filepath.Join(workDir, "../test-assets/test-dev-release-cache")

	release, err := NewDevRelease(emptyDevReleasePath, "", "", emptyDevReleaseCachePath)

	assert.NoError(err)
	assert.NotNil(release)

	assert.Len(release.Packages, 2)

	barJob, err := release.LookupJob("bar")
	assert.NoError(err)

	tempDir, err := ioutil.TempDir("", "fissile-tests")
	assert.NoError(err)
	defer os.RemoveAll(tempDir)

	extractedPath, err := barJob.Extract(tempDir)
	assert.NoError(err)

	assert.Nil(util.ValidatePath(extractedPath, true, "extracted job dir"))
}
Exemplo n.º 3
0
func TestJobInfoOk(t *testing.T) {
	assert := assert.New(t)

	workDir, err := os.Getwd()
	assert.NoError(err)

	ntpReleasePath := filepath.Join(workDir, "../test-assets/ntp-release")
	ntpReleasePathCacheDir := filepath.Join(ntpReleasePath, "bosh-cache")
	release, err := NewDevRelease(ntpReleasePath, "", "", ntpReleasePathCacheDir)
	assert.NoError(err)

	assert.Len(release.Jobs, 1)
	const ntpdFingerprint = "9c168f583bc177f91e6ef6ef1eab1b4550b78b1e"
	const ntpdVersion = ntpdFingerprint
	const ntpdSHA1 = "aab8da0094ac318f790ca40c53f7a5f4e137f841"

	assert.Equal("ntpd", release.Jobs[0].Name)
	assert.Equal(ntpdFingerprint, release.Jobs[0].Version)
	assert.Equal(ntpdVersion, release.Jobs[0].Fingerprint)
	assert.Equal(ntpdSHA1, release.Jobs[0].SHA1)

	jobPath := filepath.Join(ntpReleasePathCacheDir, ntpdSHA1)
	assert.Equal(jobPath, release.Jobs[0].Path)

	err = util.ValidatePath(jobPath, false, "")
	assert.NoError(err)
}
Exemplo n.º 4
0
func (r *Release) validateDevPathStructure() error {
	if err := util.ValidatePath(r.Path, true, "release directory"); err != nil {
		return err
	}

	if err := util.ValidatePath(r.getDevReleasesDir(), true, "release 'dev_releases' directory"); err != nil {
		return err
	}

	if err := util.ValidatePath(r.getDevReleaseConfigDir(), true, "release config directory"); err != nil {
		return err
	}

	if err := util.ValidatePath(r.getDevReleaseDevConfigFile(), false, "release dev config file"); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 5
0
func (r *Release) validatePathStructure() error {
	if err := util.ValidatePath(r.Path, true, "release directory"); err != nil {
		return err
	}

	if err := util.ValidatePath(r.manifestFilePath(), false, "release manifest file"); err != nil {
		return err
	}

	if err := util.ValidatePath(r.packagesDirPath(), true, "packages directory"); err != nil {
		return err
	}

	if err := util.ValidatePath(r.jobsDirPath(), true, "jobs directory"); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 6
0
func TestJobExtractOk(t *testing.T) {
	assert := assert.New(t)

	workDir, err := os.Getwd()
	assert.NoError(err)

	ntpReleasePath := filepath.Join(workDir, "../test-assets/ntp-release")
	ntpReleasePathCacheDir := filepath.Join(ntpReleasePath, "bosh-cache")
	release, err := NewDevRelease(ntpReleasePath, "", "", ntpReleasePathCacheDir)
	assert.NoError(err)

	assert.Len(release.Jobs, 1)

	tempDir, err := ioutil.TempDir("", "fissile-tests")
	assert.NoError(err)
	defer os.RemoveAll(tempDir)

	jobDir, err := release.Jobs[0].Extract(tempDir)
	assert.NoError(err)

	assert.Nil(util.ValidatePath(jobDir, true, ""))
	assert.Nil(util.ValidatePath(filepath.Join(jobDir, "job.MF"), false, ""))
}
Exemplo n.º 7
0
func TestGenerateRoleImageDockerfileDir(t *testing.T) {
	assert := assert.New(t)

	ui := termui.New(
		&bytes.Buffer{},
		ioutil.Discard,
		nil,
	)

	workDir, err := os.Getwd()
	assert.NoError(err)

	releasePath := filepath.Join(workDir, "../test-assets/tor-boshrelease")
	releasePathCache := filepath.Join(releasePath, "bosh-cache")
	releasePathConfigSpec := filepath.Join(releasePath, "config_spec")

	compiledPackagesDir := filepath.Join(workDir, "../test-assets/tor-boshrelease-fake-compiled")
	targetPath, err := ioutil.TempDir("", "fissile-test")
	assert.NoError(err)
	defer os.RemoveAll(targetPath)

	release, err := model.NewDevRelease(releasePath, "", "", releasePathCache)
	assert.NoError(err)

	roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/tor-good.yml")
	rolesManifest, err := model.LoadRoleManifest(roleManifestPath, []*model.Release{release})
	assert.NoError(err)

	torOpinionsDir := filepath.Join(workDir, "../test-assets/tor-opinions")
	lightOpinionsPath := filepath.Join(torOpinionsDir, "opinions.yml")
	darkOpinionsPath := filepath.Join(torOpinionsDir, "dark-opinions.yml")

	roleImageBuilder, err := NewRoleImageBuilder("foo", compiledPackagesDir, targetPath, lightOpinionsPath, darkOpinionsPath, "", "3.14.15", "6.28.30", ui)
	assert.NoError(err)

	dockerfileDir, err := roleImageBuilder.CreateDockerfileDir(
		rolesManifest.Roles[0],
		releasePathConfigSpec,
	)
	assert.NoError(err)
	defer os.RemoveAll(dockerfileDir)

	assert.Equal(targetPath, filepath.Dir(dockerfileDir), "Docker file %s not created in directory %s", dockerfileDir, targetPath)

	for _, info := range []struct {
		path  string
		isDir bool
		desc  string
	}{
		{path: ".", isDir: true, desc: "role dir"},
		{path: "Dockerfile", isDir: false, desc: "Dockerfile"},
		{path: "root", isDir: true, desc: "image root"},
		{path: "root/opt/hcf/share/doc/tor/LICENSE", isDir: false, desc: "release license file"},
		{path: "root/opt/hcf/run.sh", isDir: false, desc: "run script"},
		{path: "root/opt/hcf/startup/", isDir: true, desc: "role startup scripts dir"},
		{path: "root/opt/hcf/startup/myrole.sh", isDir: false, desc: "role specific startup script"},
		{path: "root/var/vcap/jobs-src/tor/monit", isDir: false, desc: "job monit file"},
		{path: "root/var/vcap/jobs-src/tor/templates/bin/monit_debugger", isDir: false, desc: "job template file"},
		{path: "root/var/vcap/jobs-src/tor/config_spec.json", isDir: false, desc: "tor config spec"},
		{path: "root/var/vcap/jobs-src/new_hostname", isDir: true, desc: "new_hostname spec dir"},
		{path: "root/var/vcap/jobs-src/new_hostname/config_spec.json", isDir: false, desc: "new_hostname config spec"},
		{path: "root/var/vcap/packages/tor", isDir: false, desc: "package symlink"},
	} {
		path := filepath.ToSlash(filepath.Join(dockerfileDir, info.path))
		assert.NoError(util.ValidatePath(path, info.isDir, info.desc))
	}

	symlinkPath := filepath.Join(dockerfileDir, "root/var/vcap/packages/tor")
	if pathInfo, err := os.Lstat(symlinkPath); assert.NoError(err) {
		assert.Equal(os.ModeSymlink, pathInfo.Mode()&os.ModeSymlink)
		if target, err := os.Readlink(symlinkPath); assert.NoError(err) {
			pkg := getPackage(rolesManifest.Roles, "myrole", "tor", "tor")
			if assert.NotNil(pkg, "Failed to find package") {
				expectedTarget := filepath.Join("..", "packages-src", pkg.Fingerprint)
				assert.Equal(expectedTarget, target)
			}
		}
	}

	// job.MF should not be there
	assert.Error(util.ValidatePath(filepath.ToSlash(filepath.Join(dockerfileDir, "root/var/vcap/jobs-src/tor/job.MF")), false, "job manifest file"))

	// And verify the config specs are as expected
	jsonPath := filepath.Join(dockerfileDir, "root/var/vcap/jobs-src/new_hostname/config_spec.json")
	buf, err := ioutil.ReadFile(jsonPath)
	if !assert.NoError(err, "Failed to read new_hostname/config_spec.json %s\n", jsonPath) {
		return
	}
	var result map[string]interface{}
	err = json.Unmarshal(buf, &result)
	if !assert.NoError(err, "Error unmarshalling output") {
		return
	}
	assert.Empty(result["properties"].(map[string]interface{}))

	jsonPath = filepath.Join(dockerfileDir, "root/var/vcap/jobs-src/tor/config_spec.json")
	buf, err = ioutil.ReadFile(jsonPath)
	if !assert.NoError(err, "Failed to read tor/config_spec.json %s\n", jsonPath) {
		return
	}

	expectedString := `{
		"job": {
			"name": "myrole",
			"templates": [
				{"name":"new_hostname"},
				{"name":"tor"}
			]
		},
		"networks":{
			"default":{}
		},
		"parameters":{},
		"properties": {
			"tor": {
				"hashed_control_password":null,
				"hostname":"localhost",
				"private_key": null,
				"client_keys":null
			}
		}
	}`
	assert.JSONEq(expectedString, string(buf))
}