github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/baremetalintrospection/v1/introspection/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/vnpaycloud-console/gophercloud/v2"
    10  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/baremetal/inventory"
    11  	inventorytesting "github.com/vnpaycloud-console/gophercloud/v2/openstack/baremetal/inventory/testing"
    12  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/baremetalintrospection/v1/introspection"
    13  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    14  	"github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    15  )
    16  
    17  // IntrospectionListBody contains the canned body of a introspection.IntrospectionList response.
    18  const IntrospectionListBody = `
    19  {
    20    "introspection": [
    21      {
    22        "error": null,
    23        "finished": true,
    24        "finished_at": "2017-08-17T11:36:16",
    25        "links": [
    26          {
    27            "href": "http://127.0.0.1:5050/v1/introspection/05ccda19-581b-49bf-8f5a-6ded99701d87",
    28            "rel": "self"
    29          }
    30        ],
    31        "started_at": "2017-08-17T11:33:43",
    32        "state": "finished",
    33        "uuid": "05ccda19-581b-49bf-8f5a-6ded99701d87"
    34      },
    35      {
    36        "error": null,
    37        "finished": true,
    38        "finished_at": "2017-08-16T12:24:30",
    39        "links": [
    40          {
    41            "href": "http://127.0.0.1:5050/v1/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b",
    42            "rel": "self"
    43          }
    44        ],
    45        "started_at": "2017-08-16T12:22:01",
    46        "state": "finished",
    47        "uuid": "c244557e-899f-46fa-a1ff-5b2c6718616b"
    48      }
    49    ]
    50  }
    51  `
    52  
    53  // IntrospectionStatus contains the respnse of a single introspection satus.
    54  const IntrospectionStatus = `
    55  {
    56    "error": null,
    57    "finished": true,
    58    "finished_at": "2017-08-16T12:24:30",
    59    "links": [
    60      {
    61        "href": "http://127.0.0.1:5050/v1/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b",
    62        "rel": "self"
    63      }
    64    ],
    65    "started_at": "2017-08-16T12:22:01",
    66    "state": "finished",
    67    "uuid": "c244557e-899f-46fa-a1ff-5b2c6718616b"
    68  }
    69  `
    70  
    71  // IntrospectionDataJSONSample contains sample data reported by the introspection process.
    72  var IntrospectionDataJSONSample = fmt.Sprintf(`
    73  {
    74      "all_interfaces": {
    75          "eth0": {
    76              "client_id": null,
    77              "ip": "172.24.42.100",
    78              "lldp_processed": {
    79                  "switch_chassis_id": "11:22:33:aa:bb:cc",
    80                  "switch_system_name": "sw01-dist-1b-b12"
    81              },
    82              "mac": "52:54:00:4e:3d:30",
    83              "pxe": true
    84          },
    85          "eth1": {
    86              "client_id": null,
    87              "ip": "172.24.42.101",
    88              "mac": "52:54:00:47:20:4d",
    89              "pxe": false
    90          }
    91      },
    92      "boot_interface": "52:54:00:4e:3d:30",
    93      "cpu_arch": "x86_64",
    94      "cpus": 2,
    95      "error": null,
    96      "interfaces": {
    97          "eth0": {
    98              "client_id": null,
    99              "ip": "172.24.42.100",
   100              "mac": "52:54:00:4e:3d:30",
   101              "pxe": true
   102          }
   103      },
   104      "inventory": %s,
   105      "ipmi_address": "192.167.2.134",
   106      "lldp_raw": {
   107  	"eth0": [
   108  	    [
   109  		1,
   110  		"04112233aabbcc"
   111  	    ],
   112  	    [
   113  		5,
   114  		"737730312d646973742d31622d623132"
   115  	    ]
   116  	]
   117      },
   118      "local_gb": 12,
   119      "macs": [
   120          "52:54:00:4e:3d:30"
   121      ],
   122      "memory_mb": 2048,
   123      "root_disk": {
   124          "hctl": null,
   125          "model": "",
   126          "name": "/dev/vda",
   127          "rotational": true,
   128          "serial": null,
   129          "size": 13958643712,
   130          "vendor": "0x1af4",
   131          "wwn": null,
   132          "wwn_vendor_extension": null,
   133          "wwn_with_extension": null
   134      }
   135  }
   136  `, inventorytesting.InventorySample)
   137  
   138  // IntrospectionExtraHardwareJSONSample contains extra hardware sample data
   139  // reported by the introspection process.
   140  const IntrospectionExtraHardwareJSONSample = `
   141  {
   142    "cpu": {
   143      "logical": {
   144        "number": 16
   145      },
   146      "physical": {
   147        "clock": 2105032704,
   148        "cores": 8,
   149        "flags": "lm fpu fpu_exception wp vme de"
   150      }
   151    },
   152    "disk": {
   153      "sda": {
   154        "rotational": 1,
   155        "vendor": "TEST"
   156      }
   157    },
   158    "firmware": {
   159      "bios": {
   160        "date": "01/01/1970",
   161        "vendor": "test"
   162      }
   163    },
   164    "ipmi": {
   165      "Fan1A RPM": {
   166        "unit": "RPM",
   167        "value": 3120
   168      },
   169      "Fan1B RPM": {
   170        "unit": "RPM",
   171        "value": 2280
   172      }
   173    },
   174    "memory": {
   175      "bank0": {
   176        "clock": 1600000000.0,
   177        "description": "DIMM DDR3 Synchronous Registered (Buffered) 1600 MHz (0.6 ns)"
   178      },
   179      "bank1": {
   180        "clock": 1600000000.0,
   181        "description": "DIMM DDR3 Synchronous Registered (Buffered) 1600 MHz (0.6 ns)"
   182      }
   183    },
   184    "network": {
   185      "em1": {
   186        "Autonegotiate": "on",
   187        "loopback": "off [fixed]"
   188      },
   189      "p2p1": {
   190        "Autonegotiate": "on",
   191        "loopback": "off [fixed]"
   192      }
   193    },
   194    "system": {
   195      "ipmi": {
   196        "channel": 1
   197      },
   198      "kernel": {
   199        "arch": "x86_64",
   200        "version": "3.10.0"
   201      },
   202      "motherboard": {
   203        "vendor": "Test"
   204      },
   205      "product": {
   206        "name": "test",
   207        "vendor": "Test"
   208      }
   209    }
   210  }
   211  `
   212  
   213  // IntrospectionNUMADataJSONSample contains NUMA sample data
   214  // reported by the introspection process.
   215  const IntrospectionNUMADataJSONSample = `
   216  {
   217    "numa_topology": {
   218      "cpus": [
   219        {
   220          "cpu": 6,
   221          "numa_node": 1,
   222          "thread_siblings": [
   223            3,
   224            27
   225          ]
   226        },
   227        {
   228          "cpu": 10,
   229          "numa_node": 0,
   230          "thread_siblings": [
   231            20,
   232            44
   233          ]
   234        }
   235      ],
   236      "nics": [
   237        {
   238          "name": "p2p1",
   239          "numa_node": 0
   240        },
   241        {
   242          "name": "p2p2",
   243          "numa_node": 1
   244        }
   245      ],
   246      "ram": [
   247        {
   248          "numa_node": 0,
   249          "size_kb": 99289532
   250        },
   251        {
   252          "numa_node": 1,
   253          "size_kb": 100663296
   254        }
   255      ]
   256    }
   257  }
   258  `
   259  
   260  var (
   261  	fooTimeStarted, _  = time.Parse(gophercloud.RFC3339NoZ, "2017-08-17T11:33:43")
   262  	fooTimeFinished, _ = time.Parse(gophercloud.RFC3339NoZ, "2017-08-17T11:36:16")
   263  	IntrospectionFoo   = introspection.Introspection{
   264  		Finished:   true,
   265  		State:      "finished",
   266  		Error:      "",
   267  		UUID:       "05ccda19-581b-49bf-8f5a-6ded99701d87",
   268  		StartedAt:  fooTimeStarted,
   269  		FinishedAt: fooTimeFinished,
   270  		Links: []any{
   271  			map[string]any{
   272  				"href": "http://127.0.0.1:5050/v1/introspection/05ccda19-581b-49bf-8f5a-6ded99701d87",
   273  				"rel":  "self",
   274  			},
   275  		},
   276  	}
   277  
   278  	barTimeStarted, _  = time.Parse(gophercloud.RFC3339NoZ, "2017-08-16T12:22:01")
   279  	barTimeFinished, _ = time.Parse(gophercloud.RFC3339NoZ, "2017-08-16T12:24:30")
   280  	IntrospectionBar   = introspection.Introspection{
   281  		Finished:   true,
   282  		State:      "finished",
   283  		Error:      "",
   284  		UUID:       "c244557e-899f-46fa-a1ff-5b2c6718616b",
   285  		StartedAt:  barTimeStarted,
   286  		FinishedAt: barTimeFinished,
   287  		Links: []any{
   288  			map[string]any{
   289  				"href": "http://127.0.0.1:5050/v1/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b",
   290  				"rel":  "self",
   291  			},
   292  		},
   293  	}
   294  
   295  	IntrospectionDataRes = introspection.Data{
   296  		CPUArch: "x86_64",
   297  		MACs:    []string{"52:54:00:4e:3d:30"},
   298  		RootDisk: inventory.RootDiskType{
   299  			Rotational: true,
   300  			Model:      "",
   301  			Name:       "/dev/vda",
   302  			Size:       13958643712,
   303  			Vendor:     "0x1af4",
   304  		},
   305  		Interfaces: map[string]introspection.BaseInterfaceType{
   306  			"eth0": {
   307  				IP:  "172.24.42.100",
   308  				MAC: "52:54:00:4e:3d:30",
   309  				PXE: true,
   310  			},
   311  		},
   312  		CPUs:          2,
   313  		BootInterface: "52:54:00:4e:3d:30",
   314  		MemoryMB:      2048,
   315  		IPMIAddress:   "192.167.2.134",
   316  		Inventory:     inventorytesting.Inventory,
   317  		Error:         "",
   318  		LocalGB:       12,
   319  		AllInterfaces: map[string]introspection.BaseInterfaceType{
   320  			"eth1": {
   321  				IP:  "172.24.42.101",
   322  				MAC: "52:54:00:47:20:4d",
   323  				PXE: false,
   324  			},
   325  			"eth0": {
   326  				IP:  "172.24.42.100",
   327  				MAC: "52:54:00:4e:3d:30",
   328  				PXE: true,
   329  				LLDPProcessed: map[string]any{
   330  					"switch_chassis_id":  "11:22:33:aa:bb:cc",
   331  					"switch_system_name": "sw01-dist-1b-b12",
   332  				},
   333  			},
   334  		},
   335  		RawLLDP: map[string][]inventory.LLDPTLVType{
   336  			"eth0": {
   337  				{
   338  					Type:  1,
   339  					Value: "04112233aabbcc",
   340  				},
   341  				{
   342  					Type:  5,
   343  					Value: "737730312d646973742d31622d623132",
   344  				},
   345  			},
   346  		},
   347  	}
   348  
   349  	IntrospectionExtraHardware = inventory.ExtraDataType{
   350  		CPU: inventory.ExtraDataSection{
   351  			"logical": map[string]any{
   352  				"number": float64(16),
   353  			},
   354  			"physical": map[string]any{
   355  				"clock": float64(2105032704),
   356  				"cores": float64(8),
   357  				"flags": "lm fpu fpu_exception wp vme de",
   358  			},
   359  		},
   360  		Disk: inventory.ExtraDataSection{
   361  			"sda": map[string]any{
   362  				"rotational": float64(1),
   363  				"vendor":     "TEST",
   364  			},
   365  		},
   366  		Firmware: inventory.ExtraDataSection{
   367  			"bios": map[string]any{
   368  				"date":   "01/01/1970",
   369  				"vendor": "test",
   370  			},
   371  		},
   372  		IPMI: inventory.ExtraDataSection{
   373  			"Fan1A RPM": map[string]any{
   374  				"unit":  "RPM",
   375  				"value": float64(3120),
   376  			},
   377  			"Fan1B RPM": map[string]any{
   378  				"unit":  "RPM",
   379  				"value": float64(2280),
   380  			},
   381  		},
   382  		Memory: inventory.ExtraDataSection{
   383  			"bank0": map[string]any{
   384  				"clock":       1600000000.0,
   385  				"description": "DIMM DDR3 Synchronous Registered (Buffered) 1600 MHz (0.6 ns)",
   386  			},
   387  			"bank1": map[string]any{
   388  				"clock":       1600000000.0,
   389  				"description": "DIMM DDR3 Synchronous Registered (Buffered) 1600 MHz (0.6 ns)",
   390  			},
   391  		},
   392  		Network: inventory.ExtraDataSection{
   393  			"em1": map[string]any{
   394  				"Autonegotiate": "on",
   395  				"loopback":      "off [fixed]",
   396  			},
   397  			"p2p1": map[string]any{
   398  				"Autonegotiate": "on",
   399  				"loopback":      "off [fixed]",
   400  			},
   401  		},
   402  		System: inventory.ExtraDataSection{
   403  			"ipmi": map[string]any{
   404  				"channel": float64(1),
   405  			},
   406  			"kernel": map[string]any{
   407  				"arch":    "x86_64",
   408  				"version": "3.10.0",
   409  			},
   410  			"motherboard": map[string]any{
   411  				"vendor": "Test",
   412  			},
   413  			"product": map[string]any{
   414  				"name":   "test",
   415  				"vendor": "Test",
   416  			},
   417  		},
   418  	}
   419  
   420  	IntrospectionNUMA = inventory.NUMATopology{
   421  		CPUs: []inventory.NUMACPU{
   422  			{
   423  				CPU:            6,
   424  				NUMANode:       1,
   425  				ThreadSiblings: []int{3, 27},
   426  			},
   427  			{
   428  				CPU:            10,
   429  				NUMANode:       0,
   430  				ThreadSiblings: []int{20, 44},
   431  			},
   432  		},
   433  		NICs: []inventory.NUMANIC{
   434  			{
   435  				Name:     "p2p1",
   436  				NUMANode: 0,
   437  			},
   438  			{
   439  				Name:     "p2p2",
   440  				NUMANode: 1,
   441  			},
   442  		},
   443  		RAM: []inventory.NUMARAM{
   444  			{
   445  				NUMANode: 0,
   446  				SizeKB:   99289532,
   447  			},
   448  			{
   449  				NUMANode: 1,
   450  				SizeKB:   100663296,
   451  			},
   452  		},
   453  	}
   454  )
   455  
   456  // HandleListIntrospectionsSuccessfully sets up the test server to respond to a server ListIntrospections request.
   457  func HandleListIntrospectionsSuccessfully(t *testing.T) {
   458  	th.Mux.HandleFunc("/introspection", func(w http.ResponseWriter, r *http.Request) {
   459  		th.TestMethod(t, r, "GET")
   460  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   461  		w.Header().Add("Content-Type", "application/json")
   462  		if err := r.ParseForm(); err != nil {
   463  			t.Errorf("Failed to parse request form %v", err)
   464  		}
   465  
   466  		marker := r.Form.Get("marker")
   467  
   468  		switch marker {
   469  		case "":
   470  			fmt.Fprint(w, IntrospectionListBody)
   471  
   472  		case "c244557e-899f-46fa-a1ff-5b2c6718616b":
   473  			fmt.Fprint(w, `{ "introspection": [] }`)
   474  
   475  		default:
   476  			t.Fatalf("/introspection invoked with unexpected marker=[%s]", marker)
   477  		}
   478  	})
   479  }
   480  
   481  // HandleGetIntrospectionStatusSuccessfully sets up the test server to respond to a GetIntrospectionStatus request.
   482  func HandleGetIntrospectionStatusSuccessfully(t *testing.T) {
   483  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b", func(w http.ResponseWriter, r *http.Request) {
   484  		th.TestMethod(t, r, "GET")
   485  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   486  		th.TestHeader(t, r, "Accept", "application/json")
   487  		fmt.Fprint(w, IntrospectionStatus)
   488  	})
   489  }
   490  
   491  // HandleStartIntrospectionSuccessfully sets up the test server to respond to a StartIntrospection request.
   492  func HandleStartIntrospectionSuccessfully(t *testing.T) {
   493  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b", func(w http.ResponseWriter, r *http.Request) {
   494  		th.TestMethod(t, r, "POST")
   495  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   496  		w.WriteHeader(http.StatusAccepted)
   497  	})
   498  }
   499  
   500  // HandleAbortIntrospectionSuccessfully sets up the test server to respond to an AbortIntrospection request.
   501  func HandleAbortIntrospectionSuccessfully(t *testing.T) {
   502  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b/abort", func(w http.ResponseWriter, r *http.Request) {
   503  		th.TestMethod(t, r, "POST")
   504  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   505  		w.WriteHeader(http.StatusAccepted)
   506  	})
   507  }
   508  
   509  // HandleGetIntrospectionDataSuccessfully sets up the test server to respond to a GetIntrospectionData request.
   510  func HandleGetIntrospectionDataSuccessfully(t *testing.T) {
   511  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b/data", func(w http.ResponseWriter, r *http.Request) {
   512  		th.TestMethod(t, r, "GET")
   513  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   514  		th.TestHeader(t, r, "Accept", "application/json")
   515  
   516  		fmt.Fprint(w, IntrospectionDataJSONSample)
   517  	})
   518  }
   519  
   520  // HandleReApplyIntrospectionSuccessfully sets up the test server to respond to a ReApplyIntrospection request.
   521  func HandleReApplyIntrospectionSuccessfully(t *testing.T) {
   522  	th.Mux.HandleFunc("/introspection/c244557e-899f-46fa-a1ff-5b2c6718616b/data/unprocessed", func(w http.ResponseWriter, r *http.Request) {
   523  		th.TestMethod(t, r, "POST")
   524  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   525  		w.WriteHeader(http.StatusAccepted)
   526  	})
   527  }