Esempio n. 1
0
func TestComputeSysMetrics(t *testing.T) {
	defer resetMetrics()

	instMetrics := make(map[string]data.MetricData)
	instMetrics["instance1_1"] = data.MetricData{
		BaseMetrics: map[string]float64{
			enum.METRIC_CPU_AVG.ToString(): 0.4,
			enum.METRIC_MEM_AVG.ToString(): 0.4,
		},
	}
	instMetrics["instance1_2"] = data.MetricData{
		BaseMetrics: map[string]float64{
			enum.METRIC_CPU_AVG.ToString(): 0.6,
			enum.METRIC_MEM_AVG.ToString(): 0.6,
		},
	}
	instMetrics["instance2_1"] = data.MetricData{
		BaseMetrics: map[string]float64{
			enum.METRIC_CPU_AVG.ToString(): 0.8,
			enum.METRIC_MEM_AVG.ToString(): 0.8,
		},
	}

	res.CreateMockResources(4, "1G", 0, "0G")
	sysMet := computeSysMetrics(instMetrics)
	assert.NotEmpty(t, sysMet)
	assert.InEpsilon(t, 0.65, sysMet.BaseMetrics[enum.METRIC_CPU_AVG.ToString()], 0.0001)
}
Esempio n. 2
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)
}
Esempio n. 3
0
func TestCreateCpusetCpus(t *testing.T) {
	resources.CreateMockResources(2, "1G", 0, "0G")
	empty := ""
	core0 := "0"
	var cpusetcpus string

	cpusetcpus = createCpusetCpus(empty, 1)
	assert.Equal(t, "0", cpusetcpus)

	cpusetcpus = createCpusetCpus(core0, 1)
	assert.Equal(t, "0", cpusetcpus)

	cpusetcpus = createCpusetCpus(empty, 0)
	assert.Equal(t, "0", cpusetcpus)
}
Esempio n. 4
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)
}
Esempio n. 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)
}
Esempio n. 6
0
func init() {
	res.CreateMockResources(1, "1G", 0, "0G")
	resetMockServices()
	Initialize(srv.List())
}