()
| 156 | } |
| 157 | |
| 158 | func (s *containerTestSuite) TestContainer_LoadFromDB() { |
| 159 | args := db.InstanceArgs{ |
| 160 | Type: instancetype.Container, |
| 161 | Ephemeral: false, |
| 162 | Config: map[string]string{"security.privileged": "true"}, |
| 163 | Devices: deviceConfig.Devices{ |
| 164 | "eth0": deviceConfig.Device{ |
| 165 | "type": "nic", |
| 166 | "nictype": "bridged", |
| 167 | "parent": "unknownbr0", |
| 168 | }, |
| 169 | }, |
| 170 | Name: "testFoo", |
| 171 | } |
| 172 | |
| 173 | state := s.d.State() |
| 174 | |
| 175 | err := state.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error { |
| 176 | _, err := tx.CreateNetwork(ctx, api.ProjectDefaultName, "unknownbr0", "", db.NetworkTypeBridge, nil) |
| 177 | |
| 178 | return err |
| 179 | }) |
| 180 | s.Req.Nil(err) |
| 181 | |
| 182 | // Create the container |
| 183 | c, op, _, err := instance.CreateInternal(s.d.State(), args, nil, true, true, false) |
| 184 | s.Req.Nil(err) |
| 185 | op.Done(nil) |
| 186 | defer func() { _ = c.Delete(true, true) }() |
| 187 | |
| 188 | poolName, err := c.StoragePool() |
| 189 | s.Req.Nil(err) |
| 190 | |
| 191 | pool, err := storagePools.LoadByName(state, poolName) |
| 192 | s.Req.Nil(err) |
| 193 | |
| 194 | err = state.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error { |
| 195 | _, err = tx.CreateStoragePoolVolume(ctx, c.Project().Name, c.Name(), "", db.StoragePoolVolumeContentTypeFS, pool.ID(), nil, db.StoragePoolVolumeContentTypeFS, time.Now()) |
| 196 | |
| 197 | return err |
| 198 | }) |
| 199 | s.Req.Nil(err) |
| 200 | |
| 201 | // Load the container and trigger initLXC() |
| 202 | c2, err := instance.LoadByProjectAndName(state, "default", "testFoo") |
| 203 | c2.IsRunning() |
| 204 | s.Req.Nil(err) |
| 205 | |
| 206 | hostInterfaces, _ := net.Interfaces() |
| 207 | |
| 208 | apiC1, etagC1, err := c.RenderFull(hostInterfaces) |
| 209 | s.Req.Nil(err) |
| 210 | |
| 211 | apiC2, etagC2, err := c2.RenderFull(hostInterfaces) |
| 212 | s.Req.Nil(err) |
| 213 | |
| 214 | s.Equal(etagC1, etagC2) |
| 215 | s.Exactly( |
nothing calls this directly
no test coverage detected