Beispiel #1
0
func TestBuildConfig(t *testing.T) {
	defer cfg.CleanServices()
	services := service.CreateMockServices()
	cfg.SetServices(services)
	resources.CreateMockResources(2, "1G", 0, "0G")
	ports1 := map[string]string{
		"50100": "50100",
	}
	resources.InitializeServiceAvailablePorts("service1", ports1)
	service1, _ := service.GetServiceByName("service1")

	config := buildConfig(service1, enum.START)
	assert.Equal(t, "0", config.HostConfig.CpusetCpus)
}
Beispiel #2
0
func TestGetTargetService(t *testing.T) {
	defer cfg.CleanServices()
	services := service.CreateMockServices()
	cfg.SetServices(services)

	var srv *cfg.Service
	srv = getTargetService("service1")
	assert.Equal(t, "service1", srv.Name)

	srv = getTargetService("noservice")
	assert.Equal(t, "noservice", srv.Name)

	srv = getTargetService("pippo")
	assert.Equal(t, "noservice", srv.Name)
}
Beispiel #3
0
func TestCreateHostConfig(t *testing.T) {
	defer cfg.CleanServices()
	services := service.CreateMockServices()
	cfg.SetServices(services)
	resources.CreateMockResources(2, "1G", 0, "0G")
	ports1 := map[string]string{
		"50100": "50100",
	}
	resources.InitializeServiceAvailablePorts("service1", ports1)
	service1, _ := service.GetServiceByName("service1")

	hostConfigStop := createHostConfig(service1, enum.STOP)
	assert.Equal(t, hostConfigStop.CpusetCpus, "")

	hostConfigStart := createHostConfig(service1, enum.START)
	assert.Equal(t, hostConfigStart.CpusetCpus, "0")
	assert.Len(t, hostConfigStart.PortBindings, 1)
}
Beispiel #4
0
func TestUpdateMetrics(t *testing.T) {
	cfg.SetServices(service.CreateMockServices())

	updateMetrics()
	assert.Equal(t, 0.0, Metrics().Service["service1"].Stats.BaseMetrics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.0, Metrics().Service["service2"].Analytics.BaseAnalytics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, "noaction", Metrics().Policy.Name)

	data.SaveMockStats()
	data.SaveMockAnalytics()
	data.SaveSharedCluster(data.CreateMockShared())
	plc := data.CreateMockPolicy("policy", 1.0, []string{"pippo"}, map[string][]enum.Action{})
	data.SavePolicy(plc)
	updateMetrics()
	assert.Equal(t, 0.6, Metrics().Service["service1"].Stats.BaseMetrics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.1, Metrics().Service["service2"].Analytics.BaseAnalytics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.6, metrics.Service["service1"].Shared.BaseShared[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, "policy", Metrics().Policy.Name)
}
Beispiel #5
0
func TestCreateContainerConfig(t *testing.T) {
	defer cfg.CleanServices()
	services := service.CreateMockServices()
	cfg.SetServices(services)
	resources.CreateMockResources(2, "1G", 0, "0G")
	service1 := "service1"
	id1 := "pippo"
	availablePorts1 := map[string]string{
		"50100": "50100",
	}
	ports1 := map[string][]string{
		"50100": []string{"50100"},
	}
	resources.InitializeServiceAvailablePorts(service1, availablePorts1)
	resources.AssignSpecifiPortsToService(service1, id1, ports1)
	srv1, _ := service.GetServiceByName(service1)

	containerConfigStop := createContainerConfig(srv1, enum.STOP)
	assert.Empty(t, containerConfigStop.ExposedPorts)
	containerConfigStart := createContainerConfig(srv1, enum.START)
	assert.NotEmpty(t, containerConfigStart.ExposedPorts)
}
Beispiel #6
0
func resetMockServices() {
	mockServices := srv.CreateMockServices()
	cfg.SetServices(mockServices)
}
Beispiel #7
0
func CreateMockMetrics() GruMetric {
	cfg.SetServices(service.CreateMockServices())
	mockMetrics := newMetrics()
	return mockMetrics
}