Open Kilda Java Documentation
CleanupSteps.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.atdd.staging.steps;
17 
18 import static java.lang.String.format;
19 import static org.hamcrest.MatcherAssert.assertThat;
20 import static org.hamcrest.Matchers.empty;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertTrue;
23 
27 
28 import cucumber.api.java.en.Given;
29 import cucumber.api.java8.En;
30 import lombok.extern.slf4j.Slf4j;
31 import org.springframework.beans.factory.annotation.Autowired;
32 
33 @Slf4j
34 public class CleanupSteps implements En {
35 
36  @Autowired
37  private NorthboundService northboundService;
38 
39  @Autowired
40  private TopologyDefinition topologyDefinition;
41 
42  @Autowired
43  private FloodlightService floodlightService;
44 
45  @Given("^a clean topology with no flows and no discrepancies in switch rules and meters")
46  public void cleanupFlowsAndSwitches() {
47  northboundService.deleteAllFlows();
48  assertTrue(northboundService.getAllFlows().isEmpty());
49 
50  topologyDefinition.getActiveSwitches().stream()
51  .peek(sw -> northboundService.deleteSwitchRules(sw.getDpId()))
52  .map(sw -> northboundService.synchronizeSwitchRules(sw.getDpId()))
53  .forEach(rulesSyncResult -> {
54  assertThat(rulesSyncResult.getExcessRules(), empty());
55  assertEquals(0,
56  rulesSyncResult.getMissingRules().size() - rulesSyncResult.getInstalledRules().size());
57  });
58 
59  topologyDefinition.getActiveSwitches()
60  .forEach(sw -> {
61  try {
62  assertThat(format("Switch %s has unexpected meters installed", sw),
63  floodlightService.getMeters(sw.getDpId()).values(), empty());
64  } catch (UnsupportedOperationException ex) {
65  //TODO: a workaround for not implemented dumpMeters on OF_12 switches.
66  log.warn("Switch {} doesn't support dumping of meters. {}", sw.getDpId(), ex.getMessage());
67  }
68  });
69  }
70 }