Ejemplo n.º 1
0
func (p sfdiskPartitioner) Partition(devicePath string, partitions []Partition) (err error) {
	if p.diskMatchesPartitions(devicePath, partitions) {
		boshlog.Info(p.logTag, "%s already partitioned as expected, skipping", devicePath)
		return
	}

	sfdiskPartitionTypes := map[PartitionType]string{
		PartitionTypeSwap:  "S",
		PartitionTypeLinux: "L",
	}

	sfdiskInput := ""
	for index, partition := range partitions {
		sfdiskPartitionType := sfdiskPartitionTypes[partition.Type]
		partitionSize := fmt.Sprintf("%d", partition.SizeInMb)

		if index == len(partitions)-1 {
			partitionSize = ""
		}

		sfdiskInput = sfdiskInput + fmt.Sprintf(",%s,%s\n", partitionSize, sfdiskPartitionType)
	}
	boshlog.Info(p.logTag, "Partitioning %s with %s", devicePath, sfdiskInput)

	_, _, err = p.cmdRunner.RunCommandWithInput(sfdiskInput, "sfdisk", "-uM", devicePath)
	if err != nil {
		err = bosherr.WrapError(err, "Shelling out to sfdisk")
	}
	return
}
Ejemplo n.º 2
0
func TestInfo(t *testing.T) {
	stdout, _ := captureOutputs(func() {
		logger := NewLogger(LEVEL_INFO)
		logger.Info("TAG", "some %s info to log", "awesome")
	})

	matcher, _ := regexp.Compile(expectedLogFormat("TAG", "INFO - some awesome info to log"))
	assert.True(t, matcher.Match(stdout))
}
Ejemplo n.º 3
0
func TestLogLevelError(t *testing.T) {
	stdout, stderr := captureOutputs(func() {
		logger := NewLogger(LEVEL_ERROR)
		logger.Debug("DEBUG", "some debug log")
		logger.Info("INFO", "some info log")
		logger.Error("ERROR", "some error log")
	})

	assert.NotContains(t, string(stdout), "DEBUG")
	assert.NotContains(t, string(stdout), "INFO")
	assert.Contains(t, string(stderr), "ERROR")
}
Ejemplo n.º 4
0
	Expect(err).ToNot(HaveOccurred())

	stdout = <-outC
	stderr = <-errC

	os.Stdout = oldStdout
	os.Stderr = oldStderr

	return
}

var _ = Describe("Logger", func() {
	It("info", func() {
		stdout, _ := captureOutputs(func() {
			logger := NewLogger(LevelInfo)
			logger.Info("TAG", "some %s info to log", "awesome")
		})

		matcher, _ := regexp.Compile(expectedLogFormat("TAG", "INFO - some awesome info to log"))
		Expect(matcher.Match(stdout)).To(BeTrue())
	})

	It("debug", func() {
		stdout, _ := captureOutputs(func() {
			logger := NewLogger(LevelDebug)
			logger.Debug("TAG", "some %s info to log", "awesome")
		})

		matcher, _ := regexp.Compile(expectedLogFormat("TAG", "DEBUG - some awesome info to log"))
		Expect(matcher.Match(stdout)).To(BeTrue())
	})
Ejemplo n.º 5
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("info", func() {
			stdout, _ := captureOutputs(func() {
				logger := NewLogger(LEVEL_INFO)
				logger.Info("TAG", "some %s info to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "INFO - some awesome info to log"))
			assert.True(GinkgoT(), matcher.Match(stdout))
		})
		It("debug", func() {

			stdout, _ := captureOutputs(func() {
				logger := NewLogger(LEVEL_DEBUG)
				logger.Debug("TAG", "some %s info to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "DEBUG - some awesome info to log"))
			assert.True(GinkgoT(), matcher.Match(stdout))
		})
		It("debug with details", func() {

			stdout, _ := captureOutputs(func() {
				logger := NewLogger(LEVEL_DEBUG)
				logger.DebugWithDetails("TAG", "some info to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "DEBUG - some info to log"))
			assert.True(GinkgoT(), matcher.Match(stdout))

			assert.Contains(GinkgoT(), string(stdout), "\n********************\nawesome\n********************")
		})
		It("error", func() {

			_, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_ERROR)
				logger.Error("TAG", "some %s info to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "ERROR - some awesome info to log"))
			assert.True(GinkgoT(), matcher.Match(stderr))
		})
		It("error with details", func() {

			_, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_ERROR)
				logger.ErrorWithDetails("TAG", "some error to log", "awesome")
			})

			matcher, _ := regexp.Compile(expectedLogFormat("TAG", "ERROR - some error to log"))
			assert.True(GinkgoT(), matcher.Match(stderr))

			assert.Contains(GinkgoT(), string(stderr), "\n********************\nawesome\n********************")
		})
		It("log level debug", func() {

			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_DEBUG)
				logger.Debug("DEBUG", "some debug log")
				logger.Info("INFO", "some info log")
				logger.Error("ERROR", "some error log")
			})

			assert.Contains(GinkgoT(), string(stdout), "DEBUG")
			assert.Contains(GinkgoT(), string(stdout), "INFO")
			assert.Contains(GinkgoT(), string(stderr), "ERROR")
		})
		It("log level info", func() {

			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_INFO)
				logger.Debug("DEBUG", "some debug log")
				logger.Info("INFO", "some info log")
				logger.Error("ERROR", "some error log")
			})

			assert.NotContains(GinkgoT(), string(stdout), "DEBUG")
			assert.Contains(GinkgoT(), string(stdout), "INFO")
			assert.Contains(GinkgoT(), string(stderr), "ERROR")
		})
		It("log level error", func() {

			stdout, stderr := captureOutputs(func() {
				logger := NewLogger(LEVEL_ERROR)
				logger.Debug("DEBUG", "some debug log")
				logger.Info("INFO", "some info log")
				logger.Error("ERROR", "some error log")
			})

			assert.NotContains(GinkgoT(), string(stdout), "DEBUG")
			assert.NotContains(GinkgoT(), string(stdout), "INFO")
			assert.Contains(GinkgoT(), string(stderr), "ERROR")
		})
	})
}