summaryrefslogtreecommitdiffstats
path: root/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java
blob: 96af900095fb91531adc7badff0d52f7729fdaac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.verification.spec;

import com.yahoo.vespa.hosted.node.verification.Main;
import com.yahoo.vespa.hosted.node.verification.mock.MockCommandExecutor;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * @author freva
 */
public class SpecVerifierTest {

    private static final String RESOURCE_PATH = "src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources";
    private static final String CPU_INFO_PATH = RESOURCE_PATH + "/cpuinfoTest";
    private static final String MEMORY_INFO_PATH = RESOURCE_PATH + "/meminfoTest";
    private static final String FAST_DISK_TYPE_INFO_PATH = RESOURCE_PATH + "/DiskTypeFastDisk";
    private static final String DISK_SIZE_INFO_PATH = RESOURCE_PATH + "/filesize";
    private static final String NET_INTERFACE_INFO_PATH = RESOURCE_PATH + "/ifconfig";
    private static final String NET_INTERFACE_SPEED_INFO_PATH = RESOURCE_PATH + "/eth0";
    private static final String PING_RESPONSE = RESOURCE_PATH + "/validpingresponse";
    private final MockCommandExecutor commandExecutor = new MockCommandExecutor();


    @Test
    public void spec_verification_with_failures() throws Exception {
        commandExecutor.addCommand("cat " + CPU_INFO_PATH);
        commandExecutor.addCommand("cat " + MEMORY_INFO_PATH);
        commandExecutor.addCommand("cat " + FAST_DISK_TYPE_INFO_PATH);
        commandExecutor.addCommand("cat " + DISK_SIZE_INFO_PATH);
        commandExecutor.addCommand("cat " + NET_INTERFACE_INFO_PATH);
        commandExecutor.addCommand("cat " + NET_INTERFACE_SPEED_INFO_PATH);
        commandExecutor.addCommand("cat " + PING_RESPONSE);

        String result = Main.execute(new String[] {
                "specification",
                "-d", "2500",
                "-m", "64",
                "-c", "1.5",
                "-s", "true",
                "-b", "10000.0",
                "-i", "10.11.12.13,::1234"
        }, commandExecutor);

        assertEquals(
                "{\"specVerificationReport\":{\"" +
                        "actualMemoryAvailable\":4.042128,\"" +
                        "actualDiskSpaceAvailable\":1760.0,\"" +
                        "actualInterfaceSpeed\":1000.0,\"" +
                        "actualcpuCores\":4,\"" +
                        "faultyIpAddresses\":[\"10.11.12.13\",\"0:0:0:0:0:0:0:1234\"]}}", result);
    }

    @Test
    public void benchmark_with_no_failures() throws Exception {
        commandExecutor.addCommand("cat " + CPU_INFO_PATH);
        commandExecutor.addCommand("cat " + MEMORY_INFO_PATH);
        commandExecutor.addCommand("cat " + FAST_DISK_TYPE_INFO_PATH);
        commandExecutor.addCommand("cat " + DISK_SIZE_INFO_PATH);
        commandExecutor.addCommand("cat " + NET_INTERFACE_INFO_PATH);
        commandExecutor.addCommand("cat " + NET_INTERFACE_SPEED_INFO_PATH);
        commandExecutor.addCommand("cat " + PING_RESPONSE);

        String result = Main.execute(new String[] {
                "specification",
                "-d", "1760",
                "-m", "4",
                "-c", "4",
                "-s", "true",
                "-b", "1000"
        }, commandExecutor);

        assertEquals("null", result);
    }

    @Test
    public void preserve_previous_benchmark_result() throws Exception {
        commandExecutor.addCommand("cat " + CPU_INFO_PATH);
        commandExecutor.addCommand("cat " + MEMORY_INFO_PATH);
        commandExecutor.addCommand("cat " + FAST_DISK_TYPE_INFO_PATH);
        commandExecutor.addCommand("cat " + DISK_SIZE_INFO_PATH);
        commandExecutor.addCommand("cat " + NET_INTERFACE_INFO_PATH);
        commandExecutor.addCommand("cat " + NET_INTERFACE_SPEED_INFO_PATH);
        commandExecutor.addCommand("cat " + PING_RESPONSE);

        final String previousResult = "{\"specVerificationReport\":{\"actualMemoryAvailable\":4.042128}," +
                "\"benchmarkReport\":{\"diskSpeedMbs\":49.0}}";

        String result = Main.execute(new String[] {
                "specification",
                "-d", "1760",
                "-m", "4",
                "-c", "4",
                "-s", "true",
                "-b", "1000",
                "-h", previousResult
        }, commandExecutor);

        assertEquals("{\"benchmarkReport\":{\"diskSpeedMbs\":49.0}}", result);
    }
}