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